What is the best way to deal with different user roles?

0

I need you to guide me as to the best way to control various types of users, I currently have 3 (Admin, user, editor), the role field I have in the users table as an integer (0,1,2), they can increase the number of roles. What is the best or most common way to do it?

I've seen this info in several places

Controller

private function isAdmin(){
    if (Auth::user()->user == 1) return true;
    else return false;
}

public function admin(){
    if ($this->isAdmin()){
        return View('admin.admin');
    } else{
        return redirect()->back();
    }
}

Route:

Route::get('admin', 'AdminController@admin');

View

@if (Auth::check())
   @if (Auth::user()->user == 1)
       <li><a href="{{url('admin')}}">Panel de Administrador</a></li>
   @endif
   <li><a href="{{url('user')}}">{{Auth::user()->name}}</a></li>
   <li><a href="{{url('auth/logout')}}">Salir</a></li>
@else
   <li><a href="{{url('auth/login')}}">Iniciar sesión</a></li>
@endif

But this is only for the administrator, how could I adapt it for more roles ?, what other way is it right to do it?

    
asked by Maurikius 20.11.2017 в 10:57
source

1 answer

1

After testing several ACL (Access Control List) for Laravel , I selected the following: link

Here you have a post with the two best ACL of Laravel (or at least that's what the author says) that can give you an idea of the difference of both: link

I have selected Bouncer because it is the one that best suits my needs, take a look and select the one you like the most or the easiest for you to understand.

    
answered by 21.11.2017 / 09:55
source