Is it wrong to use stab wounds in the Laravel view to present elements to the master user?

Asked

Viewed 167 times

9

I wonder if it is problematic to do this kind of validation in the views of Laravel.

Example: Only a master user can delete certain record, so I present the delete button only if the user is master (logically validating the deletions on 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

It is correct to do so or it is preferable to create new views for an administrator user if he has fewer privileges than an ordinary user?

  • 1

    I do it like this. For me it’s right and it’s working.

  • I also do rsrs, but I would like to know several opinions

1 answer

6


Actually it’s not helpers that is using is the facade class Authentication. Well the scenario is summed up, I would do to improve a View that contains this code and would call with @include in View who will use this code.

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 so would not keep repeating too much code and is not wrong in this small example, the excessive amount of this yes can be treated as a problem, or the lack of pattern in this can also become bad for those who will give maintenance.

References:

  • 1

    Thank you, I’ll change the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.