database/seeds/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();
        Permission::create(['name' => 'edit']);
        Permission::create(['name' => 'delete']);
        Permission::create(['name' => 'create']);
        Permission::create(['name' => 'view']);
        $role = Role::create(['name' => 'super-admin']);
        $role->givePermissionTo(Permission::all());
    }
public function run ( ) { app ( ) [ \ Spatie \ Permission \ PermissionRegistrar :: class ] -> forgetCachedPermissions ( ) ; Permission :: create ( [ 'name' => 'edit' ] ) ; Permission :: create ( [ 'name' => 'delete' ] ) ; Permission :: create ( [ 'name' => 'create' ] ) ; Permission :: create ( [ 'name' => 'view' ] ) ; $ 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
        $role = Role::create(['name' => 'user']);
        $role->givePermissionTo('edit');*/ // or may be done by chaining /*$role = Role::create(['name' => 'user'])
            ->givePermissionTo(['edit','view']);*/