Look into gates and policies. It does exactly what you are wanting.
Apr 12, 2018
3
Level 1
Handling a lot of roles (Currently, I have 7 roles)
Hey all,
What would be the best way to handle having a lot of roles?
In my controller, I have the following piece of code:
public function index()
{
$staff = Auth::user()->user_level == UserLevel::STAFF;
if ($staff) {
return Redirect::to(route('staff'));
}
$recruiter = Auth::user()->user_level == UserLevel::RECRUITER;
if ($recruiter) {
return view('index');
} //and so on...
}
I have researched handling roles, and I couldn't really find a way to handle a lot of roles. I thought of using Middleware for every different role, but I am not sure if that's the right way..
Please, if someone could enlighten me how I can use roles efficiently (and doing the proper redirects..), I would appreciate it a lot.
Level 67
1 like
Please or to participate in this conversation.