My User model implements the MustVerifyEmail trait, and it was working perfectly until I added an if block in my Fortify CreateNewUser class that first checks if there are any records in the User model:
public function create(array $input)
{
Validator::make($input, [
//* Validation
])->validate();
//* first check if model has any records. I just added this `if` block:
if (User::count() < 1) {
return User::create([
'name' => $input['fname'] . ' ' . $input['lname'],
'email' => $input['email'],
'gender' => $input['gender'],
'mobile_number' => $input['mobile'],
'password' => Hash::make($input['password']),
'is_active' => 1
])->roles()->attach([1, 2, 3]);
}
return User::create([
'name' => $input['fname'] . ' ' . $input['lname'],
'email' => $input['email'],
'gender' => $input['gender'],
'mobile_number' => $input['mobile'],
'password' => Hash::make($input['password']),
]);
}
Now when the first user registers, I get the error: Illuminate\Auth\SessionGuard::login(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\Authenticatable, null given which was not happening before. The second, third and other registering users are sent the email verification link after registration, which is what I want for all registering users. How can I fix this so that even the first user verifies his email?