W
W
WebDev2015-12-13 21:51:15
Laravel
WebDev, 2015-12-13 21:51:15

Separation of roles in laravel?

Hello everyone, tell me how to properly organize such a structure: there is a user with the admin role, and there is a buyer with the role. Both of them inherit the functionality of the standard User model class, but they have a number of differences. For them, I created 2 models that inherit User. How can I make it so that when a new record is created via new Admin(), a record is automatically created in the users table and linked to the admins table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
D', 2015-12-13
@kirill-93

It is better to make through standard division into roles.
Use https://github.com/Zizaco/entrust
With several models of hemorrhoids, you won't get enough.
If you want to eat a cactus, then:
- In the Admin model, specify protected $table = 'users';
- In the AppServiceProvider, in the boot method, we write

Admin::created(function ($model) {
  // Тут связываем модель с таблицей admins
});

Thus, after creating a record in the users table, the created hook will work, and do whatever you want in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question