Have you got any permissions for saving users in role_has_permissions?
How does the 'associate' method work behind the scenes?
I am using the spatie/laravel-permission in my project. I am hiding some routes behind their middleware to avoid unauthorized users to use them. But I am having a problem. When I do this:
$profile->user()->associate($user);
as part of the process of creating a user, I get the "You do not have access to do that." alert.
The user gets created, the profile gets created but they do not get associated to each other. If I manually assign the corresponding IDs it works fine.
I am using the associate() method in other part of the application intended to be used by another role and it works fine, so my guess is that the associate()method is trying to do something I don't know and somewhere it's getting rejected by the role/permission middleware.
What could it be?
I found the problem and now I feel very dumb. After the user is created, on EntityController I was redirecting to the wrong route, one protected by the role middleware for admins only
public function storeCommerce(StoreCommerceRequest $request)
{
$this->entityRepository->createCommerce($request->only(
//etc
));
return redirect()->route('admin.entity.users')->withFlashSuccess(__('alerts.backend.users.created'));
}
And to feel even more dumb, I didn't even posted that line on my issue here...
It works now, but still I don't know why everything would work except the associate() method. any Ideas?
Please or to participate in this conversation.