@user1980 The truth is you have flexibility here and having the same protection in two places doesn't hurt anything. Generally I prefer to have middleware protection specified in the route files. I just feel like it is easier to see/understand that way. ...but the same argument could be made that having it in the controller is "cleaner" and more tucked away. As I said, my personal preference is to just have these things in the route files. Hope that helps!
Spattie roles/permissions quesiton
Hi,
Quick question please.
If you use Spattie roles/permissions and add this in every controller:
public function __construct()
{
$this->middleware('permission:games view', ['only' => ['index', '']]);
$this->middleware('permission:games add', ['only' => ['']]);
$this->middleware('permission:games update', ['only' => ['update']]);
$this->middleware('permission:games delete', ['only' => ['']]);
}
I did not add all the methods above as it is just an example.
My question is, if you create a ROLE/PERMISSIONS CRUD, would you still protect routes as, based on each role, the user has the permission to access such and such resources. But, before adding the roles/permissions via a CRUD and controllers, I have the below middleware setup.
Route::group(['middleware' => ['role:admin|user|follower']], function () {
//Controllers here
});
Shall I remove this middleware from the web.php file?
I am a bit stuck on this one because if you think about it, the role middleware is not needed if already added to all the controllers.....or shall I leave it for security purpose(in case I forget to add the roles within a controller)?
I would love yo hear from your own experience on this please.
Thanks,
Please or to participate in this conversation.