2
I would like to hide my system buttons that allow: add, edit and delete data from my templates for users who are not logged in to the system. He can be seen here: https://sirh-marcellobenigno.herokuapp.com
After some consultations, I saw that it can be done this way:
{% if request.user.is_authenticated %}
...
<button>...</button>
...
{% else %}
...
{% endif %}
However, various conditions will be added to the templates... would have some more elegant way to do this?
I had a similar problem in
Laravel 5
. The solution I had was to create the button in one view, where I passed the parameters to create the button. And there, even there already has the verification whether the user has access or not.. I only have the job to include, to verify not...– Wallace Maxters
Interesting... what were the parameters in this case? I think it might be an output yes.
– Marcello Benigno
Well, in my case I did it this way:
@if(auth()->user()->canAccess($rota))link_to_action($rota, 'adicionar', isset($params) ? $params : []
) @endif`– Wallace Maxters
It must be hard to understand. Look at these gist that gets easier
– Wallace Maxters
Thanks @Wallacemaxters, I’ll try this way.
– Marcello Benigno
It is easier to just pass the name of the url or route, than to pass and check at the same time.
– Wallace Maxters
It’s a shame I’ve touched so little with this excellent Python :D framework
– Wallace Maxters