I am trying to attach a role and update the registered_at
field in the invitations
table through the Jetstream authentication controller itself, located at App\Actions\Fortify\CreateNewUser
. I want to perform the said above function when the user creates an account.
The below code is performing the function as I wanted, It's successfully updating the registered_at
field, and attaching the role as well, but is not successfully redirecting to the dashboard.
Error
Argument 1 passed to Illuminate\Auth\SessionGuard::login() must implement interface Illuminate\Contracts\Auth\Authenticatable, null given, called in C:\xampp\htdocs\2020\vendor\laravel\fortify\src\Http\Controllers\RegisteredUserController.php on line 56
App\Actions\Fortify\CreateNewUser.php - Updated Code
public function create(array $input) {
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this - > passwordRules(),
]) - > validate();
$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
$user - > roles() - > sync('3');
$invitation = Invitation::where('email', $user - > email) - > firstOrFail();
$invitation - > registered_at = $user - > created_at;
$invitation - > save();
}
App\Actions\Fortify\CreateNewUser.php - Original Code
public function create(array $input) {
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this - > passwordRules(),
]) - > validate();
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
}