Laravel Roles and authentication to routes

12,858

Solution 1

For those in the future who are looking for this solution

http://net.tutsplus.com/tutorials/php/build-web-apps-from-scratch-with-laravel-filters-validations-and-files/

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

Share:
12,858
David Kirubi
Author by

David Kirubi

Updated on June 05, 2022

Comments

  • David Kirubi
    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
    David Kirubi almost 11 years
    Is there no way to do it using Laravel Auth?
  • Rodri_gore
    Rodri_gore almost 11 years
    Of 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
    Ren almost 11 years
    Can you add relevant information from the link to your answer? Link only answers can become useless if the link breaks.