Is it wrong to use the facades in the laravel view to display elements to the master user?

9

I wonder if it's problematic to do this type of validation in Laravel views.

Example: Only one master user can delete a certain record, so I have the delete button only if the user is master (logically validating the deletions in Controller ).

Exemplifying in code:

@if(Auth::user()->administrator)
    <a title="Excluir" href="/users/delete/{{$user->id}}">
        <i class="fa fa-trash-o" aria-hidden="true"></i>
    </a>
@endif

Is it okay to do this, or is it preferable to create new views for an admin user if he has fewer privileges than a regular user?

    
asked by anonymous 10.01.2017 / 17:15

1 answer

6

Actually it is not helpers you are using is the facade of Authentication class. Well the scenario is summarized, I would do to improve a View that contains this code and would call with @include at View that will use this code snippet.

  

botao.blade.php

@if(Auth::user()->administrator)
    <a title="Excluir" href="/users/delete/{{$user->id}}">
         <i class="fa fa-trash-o" aria-hidden="true"></i>
    </a>
@endif
  

in View

@include('botao')

At least that way I would not be repeating too much code and it is not wrong in this small example, the excessive amount of it yes can be treated as a problem, or the lack of standard in it can also become bad for the maintenance person. p>

References:

10.01.2017 / 17:28