I wonder if there's possibility, to change a little bit the approach of the permissions.
I use Spatie Roles package, where in my project I don't really use the Roles but only Permissions.
Total amount of my permissions is something like 500. So every User can have 0 or more, and also it depends of his AD group membership.
In db it's more like model_has_permissions
.
So I've created a middleware where I'm checking if the user has correct permission to the specific Post
code:
if(!Auth::user()->can($request->post->codes->code))
{
return redirect()->route('post.index')->withErrors(['No permissions to view this post!']);
} else {
return $next($request);
}
So after looking inside Debugbar, I can see that there are loaded all of Permissions. Is there a possibility to avoid that?
I've tried to query directly using Permission::where('name', 1)->get()
but it return object which looks like blank thing.
Any tips for better aproach? I'm also checking every time User is logging in if there was permission change in his account.