My UserObserver works OK after creating the first user. When I create the second user, the function returns the values of the first user, why?
In UserObserver:
class UserObserver
{
/**
* Handle the User "created" event.
*
* @param \App\Models\User $user
* @return void
*/
public function created(User $user)
{
dd($user->first()->id);
}
}
Everything is fine in the database. The next registration is correctly assigned the next id number
CodePudding user response:
If you have an instance of an User and call ->first() it will create an QueryBuilder and actually get the first. Just use the $user that is passer to the method.
public function created(User $user)
{
dd($user);
}
CodePudding user response:
I did it.
A function was the problem first() = firts user in database
