Студия разработки сайтов и приложений

Netspark.ru

User Multi-Tenancy and Observers

First, I want to admit that there are a lot of ways to implement or even think about multi-tenancy. For more thoughts on this, I recommend a wonderful presentation called Multi-Tenant Laravel by Tom Schlick. In this article, I will show multi-tenancy based on single database and Laravel Global Scopes.

Now, let’s add multi-tenancy to our database entries. Let’s imagine we have DB table called posts, and we want each user to see only their own posts.

Use Laravel Observers and Global Scopes to Create User Multi-Tenancy

Через один observer куда элегантнее, чем пихать сохраненение user id (или другой сущности-владельца!) в каждый контроллер.

Комментарии