2

I am new to Laravel and trying to use enrtust plugin for roles and permissions, but when following the instructions in the documentation, I reached the bit where I have to put the code that creates the roles and permissions, but it did not mention where I have to put it. What is the best place to put it?

Here is the code I am talking about:

$owner = new Role();
$owner->name         = 'owner';
$owner->display_name = 'Project Owner'; // optional
$owner->description  = 'User is the owner of a given project'; // 
$owner->save();

$admin = new Role();
$admin->name         = 'admin';
$admin->display_name = 'User Administrator'; // optional
$admin->description  = 'User is allowed to manage and edit other users'; 
$admin->save();
4

1 回答 1

1

我通常在这种情况下使用播种机。在此示例中,我创建RoleTableSeeder,PermissionTableSeederPermissionRoleTableSeeder.

您可以使用以下命令单独运行播种机:

php artisan db:seed --class=PermissionTableSeeder

或者您可以通过以下命令运行所有播种机:

php artisan db:seed
于 2018-01-26T18:59:29.443 回答