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();
        $permissions = [
            'role-view',
            'role-create',
            'role-edit',
            'role-delete',
            'permission-view',
            'permission-create',
            'permission-edit',
            'permission-delete',
            'user-view',
            'user-create',
            'user-edit',
            'user-delete',
          ];
        foreach ($permissions as $permission) {
            Permission::create(['name' => $permission]);
        }
        $role = Role::create(['name' => 'admin']);
        $role->syncPermissions($permissions);
        DB::table('users')->insert([
            'name' => 'Administrador',
            'email' => 'admin@gmail.com',
            'password' => bcrypt('12345678'),
            'created_at' => date('Y-m-d'),
            'updated_at' => date('Y-m-d')
        ]);
        $user = User::find(1);
        $user->assignRole('admin');
    }
public function run ( ) { app ( ) [ \ Spatie \ Permission \ PermissionRegistrar :: class ] -> forgetCachedPermissions ( ) ; $ permissions = [ 'role-view' , 'role-create' , 'role-edit' , 'role-delete' , 'permission-view' , 'permission-create' , 'permission-edit' , 'permission-delete' , 'user-view' , 'user-create' , 'user-edit' , 'user-delete' , ] ; foreach ( $ permissions as $ permission ) { Permission :: create ( [ 'name' => $ permission ] ) ; } $ role = Role :: create ( [ 'name' => 'admin' ] ) ; $ role -> syncPermissions ( $ permissions ) ; DB :: table ( 'users' ) -> insert ( [ 'name' => 'Administrador' , 'email' => 'admin@gmail.com' , 'password' => bcrypt ( '12345678' ) , 'created_at' => date ( 'Y-m-d' ) , 'updated_at' => date ( 'Y-m-d' ) ] ) ; $ user = User :: find ( 1 ) ; $ user -> assignRole ( 'admin' ) ; }
Run the database seeds.
Run the database seeds .
// Reset cached roles and permissions // create permissions // create roles and assign created permissions