Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

Default roles & permissions #897

Open ghost opened 6 years ago

ghost commented 6 years ago

How should I create default roles and permissions ?

The ones that should be by default in my app (admin role would suit me for now).

Where should I put this code so it creates automatically (somehow?)

$admin               = new Role();
$admin->name         = 'admin';
$admin->display_name = 'User Administrator';
$admin->description  = 'User is allowed to manage everything';
$admin->save();

P.S. I'm a quite a beginner in PHP and Laravel.

CamiloManrique commented 6 years ago

You should create a seeder for this. You can check the seeds documentation here https://laravel.com/docs/5.5/seeding.

Usually you run your seeders after running your migrations.

psychonetic commented 6 years ago

I think this is out of the scope of this package. It's really up to you how to create those roles and permissions and you should ask on stackoverflow or similiar. As mentioned @CamiloManrique the correct and best way would be a seeder for this.

davidvexel commented 6 years ago

https://github.com/thomasfw/RolesAndPermissionsSeeder