forgetCachedPermissions(); // Create permissions $permissions = [ 'settings.manage', 'proclamatori.manage', 'territori.manage', 'campagne.manage', 'registro.view', 'registro.export', 'territori.assign', 'territori.return', 'audit.view', 'audit.export', ]; foreach ($permissions as $permission) { Permission::firstOrCreate(['name' => $permission]); } // givePermissionTo() rather than syncPermissions(): sync *detaches* // anything not in these lists. This seeder can re-run against a // populated database (the deploy marker lives on a volume that may be // recreated), and syncing would silently revoke every permission an // administrator had granted through the UI. Granting is additive and // therefore safe to repeat. // // These lists are the baseline each role starts with, not a // continuously enforced contract. // Amministratore: all permissions $admin = Role::firstOrCreate(['name' => 'amministratore']); $admin->givePermissionTo($permissions); // Assistente: proclamatori, campagne, assign, return $assistente = Role::firstOrCreate(['name' => 'assistente']); $assistente->givePermissionTo([ 'proclamatori.manage', 'campagne.manage', 'territori.assign', 'territori.return', 'registro.view', ]); // Operatore: assign and return only $operatore = Role::firstOrCreate(['name' => 'operatore']); $operatore->givePermissionTo([ 'territori.assign', 'territori.return', ]); } }