Laravel Roles and authentication to routes
12,858
Solution 1
For those in the future who are looking for this solution
Will be very helpful, thanks Rodri for your pointer. I appreciate.
Solution 2
I recommend you the Laravel 4 Package called: ENTRUST who provide a way to add Role-based
Author by
David Kirubi
Updated on June 05, 2022Comments
-
David Kirubi almost 2 years
I am looking to archive the the following
Userlogs in -> Assigned a privilege from the DB -> They can only see allowed routes only
So far i have been able to reach here:
$user = Usercredential::where('username','=',Auth::user()->username)->get(); foreach ($user as $u ) { $status = $u->userstatus; $userPriv = $u->userpriviledge; if ($status == 0){ Session::put('user_priv',$userPriv); } else{ return Redirect::to_route('home')->with('message','Inactive users cannot login'); }
Which checks the status of the user if active or inactive then stores the priviledge in my session. What next? How do i protect my routes?
Thanks
-
David Kirubi almost 11 yearsIs there no way to do it using Laravel Auth?
-
Rodri_gore almost 11 yearsOf Course you can, take a look at the documentation four.laravel.com/docs/security and read about filters. As a personal opinion, I don't give it a try reinventing the wheel in the problem of roles and auth, thats because someone solved that problem in Laravel 4.
-
Ren almost 11 yearsCan you add relevant information from the link to your answer? Link only answers can become useless if the link breaks.