Roles in laravel

0

I am working with laravel and I am in the roles and permissions stage of my application.

In my table of users, add the one field called role.

If role = 1 then he is an administrator

if role = 2 then it is a normal user.

I would like you to agree to the type of role you logged in to see different options in the menu. I hope you can help me

My view of the menu is as follows:

 @if (Auth::guest())
 <li><a href="{{ url('/login') }}">Inicio de sesión</a></li>
 @else
              <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Alumnos <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                       <li><a href="{{ url('/alumno') }}">Alumnos inscritos</a></li>
                            <li><a href="{{ url('/alumno2') }}">Grados </a></li>
                            <li><a href="{{ url('/alumno3') }}">Materias</a></li>
                        </ul>
                       </li>


  @endif
    
asked by Estefania 16.11.2017 в 01:30
source

2 answers

-1

Since similar to your example, you should only place if in the places you want.

Ex:

@if (Auth::user()->rol==1)
    Vista para el administrador
@else
    Vista para tu usuario normal 
@endif

It's that simple, of course, if you have many more types of users this would ruin the performace.

    
answered by 16.11.2017 / 04:02
source
0

Doing what the other partner tells you would make the performance of your application really bad. Just imagine that you have 40 permission modules per view and user, it would be chaotic. To do this use GATE or this library that will be very popular and allows you to use the tag @can('permiso')

    
answered by 16.11.2017 в 10:37