json(['message' => 'forbidden'], Response::HTTP_FORBIDDEN); } $validated = $request->validated(); event(new Registered($user = $this->create($validated))); $this->guard()->login($user); /** * @var \App\Models\User|null */ $user = $this->guard()->user(); return response()->json([ 'message' => 'account created', 'name' => $user->name, 'email' => $user->email, 'preferences' => $user->preferences, 'is_admin' => $user->isAdministrator(), ], 201); } /** * Create a new user instance after a valid registration. * * @return \App\Models\User */ protected function create(array $data) { $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), ]); Log::info(sprintf('User ID #%s created', $user->id)); if (User::count() == 1) { $user->promoteToAdministrator(); $user->save(); Log::notice(sprintf('User ID #%s set as administrator', $user->id)); } return $user; } }