I am defining Gates within service provider. Like this:
$permissions = \DB::table('permissions')->whereNotNull('route_name')->get();
foreach ( $permissions as $permission) {
Gate::define($permission->route_name, function($user) use ($permission){
return $user->hasPermission($permission->route_name);
});
};
I am able to access the current user within the callback of the Gate but I cant acces the user outside the callback. Instead that above I want define the gates directly like:
$permissions = \Auth::user()->permissions();
foreach ( $permissions as $permission) {
Gate::define($permission->route_name, function($user) {
return true;
});
};
Is that possible ?
PS: I can't access auth()->user()
like in some similar questions because I am using stateless authentication without session.