N
N
Nik Gubin2016-09-05 16:36:34
Laravel
Nik Gubin, 2016-09-05 16:36:34

How to implement a common policy across different controllers in Laravel?

Good afternoon friends.
I got to the policies in Laravel and immediately the question is - is it possible to make a common policy for different controllers?
Yes, you can suggest using an intermediary in which to check the rights, but I need to process both a positive result and a negative one. If we go deeper into the task, then I have one table of users, but there is a flag that indicates whether this is an admin or a simple user. There is a personal account, which should be available only to a simple user, and a message should be displayed to the admin that he does not have rights to this section. Likewise with the basket and many others.
There is another option, in the user model I have already created two methods: isRegularUser and isSpecialUser, which return boolean values. This is a solution that I can use right now, but I would like to understand if it is possible to make a general policy in Laravel? Maybe I overlooked it, but in the manual in the "registration of policies" section it is clearly seen that each policy is tied to a specific class. Or I can bind the same policy to different classes, but what if I need to supplement the rules with a personal policy?
Again, I understand that this can be solved through the user model, but for learning purposes I decided to ask more experienced ones! Thank you for understanding.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
deadmemoras, 2016-09-05
@gubin_niko

Difficult)
In this case, you can use relationships: many to many.
For example: the role "administrator" can have many users and so on.
The documentation provides very useful information about relationships.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question