database/seeders/RolesAndPermissionsSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
        $permissions = [
           'organizations-list',
           'organizations-create',
           'organizations-edit',
           'organizations-delete',
           'settings-list',
           'settings-create',
           'settings-edit',
           'settings-delete',
           'statuses-list',
           'statuses-create',
           'statuses-edit',
           'statuses-delete',
           'applications-list',
           'applications-create',
           'applications-edit',
           'applications-delete',
           'passages-list',
           'passages-create',
           'passages-edit',
           'passages-delete'
        ];
        foreach ($permissions as $permission) {
             Permission::create(['name' => $permission]);
        }
        $role = Role::create(['name' => 'Admin'])->givePermissionTo([
           'organizations-list',
           'organizations-create',
           'organizations-edit',
           'organizations-delete',
           'settings-list',
           'settings-create',
           'settings-edit',
           'settings-delete',
           'statuses-list',
           'statuses-create',
           'statuses-edit',
           'statuses-delete',
           'applications-list',
           'passages-list'
        ]);
        $role = Role::create(['name' => 'PassOffice'])->givePermissionTo([
           'organizations-list',
           'organizations-create',
           'organizations-edit',
           'organizations-delete',
           'applications-list',
           'applications-edit',
           'passages-list',
           'passages-create',
           'passages-edit',
        ]);
        $role = Role::create(['name' => 'Organization'])->givePermissionTo([
           'applications-list',
           'applications-create',
           'applications-edit',
           'applications-delete',
           'passages-list',
           'passages-create',
           'passages-edit',
           'passages-delete'
        ]);
        $role = Role::create(['name' => 'Super-admin']);
        $role->givePermissionTo(Permission::all());
    }
public function run ( ) { app ( ) [ \ Spatie \ Permission \ PermissionRegistrar :: class ] -> forgetCachedPermissions ( ) ; $ permissions = [ 'organizations-list' , 'organizations-create' , 'organizations-edit' , 'organizations-delete' , 'settings-list' , 'settings-create' , 'settings-edit' , 'settings-delete' , 'statuses-list' , 'statuses-create' , 'statuses-edit' , 'statuses-delete' , 'applications-list' , 'applications-create' , 'applications-edit' , 'applications-delete' , 'passages-list' , 'passages-create' , 'passages-edit' , 'passages-delete' ] ; foreach ( $ permissions as $ permission ) { Permission :: create ( [ 'name' => $ permission ] ) ; } $ role = Role :: create ( [ 'name' => 'Admin' ] ) -> givePermissionTo ( [ 'organizations-list' , 'organizations-create' , 'organizations-edit' , 'organizations-delete' , 'settings-list' , 'settings-create' , 'settings-edit' , 'settings-delete' , 'statuses-list' , 'statuses-create' , 'statuses-edit' , 'statuses-delete' , 'applications-list' , 'passages-list' ] ) ; $ role = Role :: create ( [ 'name' => 'PassOffice' ] ) -> givePermissionTo ( [ 'organizations-list' , 'organizations-create' , 'organizations-edit' , 'organizations-delete' , 'applications-list' , 'applications-edit' , 'passages-list' , 'passages-create' , 'passages-edit' , ] ) ; $ role = Role :: create ( [ 'name' => 'Organization' ] ) -> givePermissionTo ( [ 'applications-list' , 'applications-create' , 'applications-edit' , 'applications-delete' , 'passages-list' , 'passages-create' , 'passages-edit' , 'passages-delete' ] ) ; $ role = Role :: create ( [ 'name' => 'Super-admin' ] ) ; $ role -> givePermissionTo ( Permission :: all ( ) ) ; }
Run the database seeds.
Run the database seeds .
// Reset cached roles and permissions // create permissions // create roles and assign created permissions // this can be done as separate statements