It looks like there is a small mistake in your UserPolicy method. The issue is with the condition that checks if the logged-in user is the same as the user being updated. You are using auth()->check() which returns a boolean indicating if the user is authenticated, not the user's ID. Instead, you should use auth()->id() or directly compare the $user object with the $model object.
Here's the corrected update method in your UserPolicy:
public function update(User $user, User $model): bool
{
return $user->hasPermissionTo('update:user') || $user->id === $model->id;
}
In this corrected version:
-
user->hasPermissionTo('update:user')checks if the user has the permission to update any user. -
$user->id === $model->idchecks if the logged-in user is the same as the user being updated, allowing users to update their own profile.
This should ensure that only users with the appropriate permission or the user themselves can update the user model.