Can you post the CheckRole code?
User roles in Laravel 6
I've been searching the net empty, and still haven't figured out what I am doing wrong!
I am trying to make a simple middleware where I decide if users has the expected roles for specific routes/Controllers. He's the data:
- The roles and user attachment of those roles is working.
- I created a middleware called "CheckRole" and in my controller I use the middleware in the constructor, i.e.
$this->middleware(['role:writer', 'role:admin']); - In Kernel.php in the
$routeMiddlewarearray, I added'role' => CheckRole::class,
All of this is working. if I log in as admin or writer, the CheckRole class passes the permission check, and proceeds to the return $next($request);
BUT - here it has already been decided that I don't have permission or something else is going wrong that denies me access to the url, and I get a "403 permission denied" request. The $request->url() is the url I asked for, but $next($request))is this 403 request.
What am I missing?
Venter på Mortens and så skulle bruge tiden på noget :)
It seems that the issue is that it runs the middleware twice and fails at the second iteration. (once for writer and one for admin). You could probably do something like this
$this->middleware(['role:writer|admin']);
else if (!$request->user()->hasAnyRole(explode("|", $role))
Please or to participate in this conversation.