Answer the question
In order to leave comments, you need to log in
How to remove ErrorException in VerifyCsrfToken.php error in laravel?
Good day to all. I am assigning user rights to access the site's admin panel and encountered an error ErrorException in VerifyCsrfToken.php Trying to get property of non-object. I cannot understand what is the problem.
controller:
public function __construct(Request $request)
{
$this->middleware(function ($request, $next) {
if(Gate::denies('VIEW_ADMIN')) {
abort(404);
}
});
}
public function boot()
{
$this->registerPolicies();
Gate::define('VIEW_ADMIN', function ($user) {
return $user->canDo('VIEW_ADMIN');
});
}
public function canDo($permission) {
foreach($this->roles as $role) {
foreach($role->permissions as $perm) {
if(str_is($permission, $perm->name)) {
return true;
} else {
return false;
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question