I look at it in stages, example:
Route::get('indexadmin', 'DogController@indexAdmin')->middleware('auth');
But I usually use route groups.
All that does is tell me someone has to be logged in to use that method, but who.
I have roles like:
roles
-------------
admin
bkeep // for bookkeeper
admin,bkeep // both roles
user
etc
On a method I verify if the required role matches the current logged in users role.
Which for admin, bookkeeper, that is enough.
However for a user who can edit their own data only, you also need a check to ensure the id of the logged in user matches the forign key id on the data in question. Something like:
if ($request->id === Auth::id()) {
return $next($request);
}
And an example of a non-laravel framework, just an example only:
// an edit example
$data['row'] = $this->Pet->getPet($petid);
Cln::chkUserId($data['row']->owner_id);
And it calls a check:
public static function chkUserId($userid)
{
if ($userid === Session::get('owner') || Session::get('isadmin') === 'admin') {
return;
}
return false;
{
You need a check of the proper id, otherwise someone could just put an id in the url, and that record would come up for an edit.
To me roles make sense, but permissions can be done in the controller and models via the correct role and correct id.
Permissions can also be redundant, Meaning as example, take the bookkeeper, of course they can view, edit, add, or whatever to bookkeeping. So if the role is bookkeeper matches, all is okay.
Permissions can allow a non bookkeeper in there, but perhaps they can only view the data.
Permissions require a lot of extra if statements, "can", "cannot", etc. Which is fine for some.
But add up the lines of code that the extra checks, "if", "can", "cannot", etc places in the code.
To me it's easier to just write an extra method for someone who can only view bookkeeping, if the role matches, all is done. None of the extra checks required.
I have seen some of the examples, and in a large system there is no telling how many "can", "cannots" are needed.
An extra method and view fulfills the same thing. As long as the persons role matches the required role for the controller method.
Of course do the permissions as you see fit.
But there are several ways of using an RBAC system. There are ways to keep it simple yet secure.