L
L
lemonlimelike2018-12-13 01:18:08
Laravel
lemonlimelike, 2018-12-13 01:18:08

How to implement access to certain data on all pages in Laravel?

Hello! I made a page with the admin panel, hung middleware on the root. I have table roles: id | user_id | role. With this table, I want to hide links (in this case, the link to the admin area) that ordinary users cannot see.
There is an option, it is in each controller to transfer the role of the user (for ordinary users = the role of user, and for admins = 'admin'), somehow it will not be very good if you do this.
And I thought about another option, make an ajax request to the server, and take the user's role from there, and show / hide certain content.
How to do it better? Or are there other options?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maddog670, 2018-12-13
@lemonlimelike

Gate https://laravel.com/docs/5.7/authorization#gates
Policy https://laravel.com/docs/5.7/authorization#creatin...
For understanding https://code.tutsplus.com/en/tutorials /gates-and-p...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question