-
app/Services/User/CreateUser.php
Open in GitHubuse App\Models\User\User; use App\Services\BaseService; class CreateUser extends BaseService { public function rules() { return [ 'account_id' => 'required|integer|exists:accounts,id', 'first_name' => 'required|max:255', 'last_name' => 'required|max:255', 'email' => 'required|email|max:255|unique:users', 'password' => 'required|min:6', 'locale' => 'nullable', 'ip_address' => 'nullable', ]; } public function execute(array $data): User { $this->validate($data); $ipAddress = $data['ip_address'] ?? RequestHelper::ip(); $user = $this->createUser($data); $user = $this->setRegionalParameters($user, $ipAddress); $user->save(); app(AcceptPolicy::class)->execute([ 'account_id' => $user->account_id, 'user_id' => $user->id, 'ip_address' => $ipAddress, ]); return $user; } // }
-
app/Http/Controllers/Auth/InvitationController.php
Open in GitHubuse App\Services\User\CreateUser; use App\Jobs\SendNewUserAlert; class InvitationController extends Controller { // protected function create(array $data, $invitation) { $user = app(CreateUser::class)->execute([ 'account_id' => $invitation->account_id, 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'email' => $data['email'], 'password' => $data['password'], 'locale' => $invitation->invitedBy->locale, 'ip_address' => RequestHelper::ip(), ]); $user->invited_by_user_id = $invitation->invited_by_user_id; $user->save(); // send me an alert SendNewUserAlert::dispatch($user); return $user; } // }