Laravel User Multi-Tenancy 3/3: Filter Multiple Models with Traits

preview_player
Показать описание
If you have the same repeating "where" condition for multiple models, you may use traits and include that trait in all those modules.

- - - - -
Support the channel by checking out my products:

- - - - -
Other places to follow:
Рекомендации по теме
Комментарии
Автор

Great video, thanks Povilas 👏🏽👏🏽.

Only thing I would change at 2:52 is rename the boot() to bootFilterByUser() and delete parent::boot().

Samuel.Mwangi
Автор

Great video, i should consider using traiits more in my projects, i actually never use them

ush
Автор

When you have a trait with the boot method, what happens if you also need to use the boot method for other things? Seems to me like traits in general should be used to _add_ methods, not override existing ones?

travholt
Автор

Hello, I am using this method to make my web app and would like to know how can we use admin to bypass all permissions? also if there is a parent account of the current user like a supervisor or manager I need them to bypass the permission as well if the user belongs under their tree, Thank you.

mindteaserhub
Автор

Hi, lets think about a hierarchical tenancy scenario im currently working on it since It is a real business need. Thanks!.

FuzzPiAndFacial
Автор

Love the video! for the case of Admin, how to deal with prevent running the trait ?

AmenAmenzo
Автор

I noticed there is an issue when setting the user id in boot method, when the save, create, update or when creating a model with the factory, particularly with a seeder, the user id might not filled as the authenticated user is not present during seeder. User id will not be set. I added a check for user id is not present before retrieving from the authenticated user.

donnaarisson
Автор

How the heck do people remember all this 😵😵‍💫

JamesAutoDude