fix to roles
This commit is contained in:
parent
ebfecb8a30
commit
9e47b399ed
|
|
@ -5,6 +5,7 @@
|
|||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class RolePermissionSeeder extends Seeder
|
||||
|
|
@ -47,10 +48,15 @@ public function run(): void
|
|||
$staff->permissions()->sync(Permission::whereIn('slug', ['create', 'read', 'update'])->pluck('id'));
|
||||
$viewer->permissions()->sync(Permission::where('slug', 'read')->pluck('id'));
|
||||
|
||||
// Optionally ensure first user is admin
|
||||
$firstUser = User::query()->orderBy('id')->first();
|
||||
if ($firstUser && ! $firstUser->roles()->where('roles.id', $admin->id)->exists()) {
|
||||
$firstUser->roles()->attach($admin->id);
|
||||
// Ensure specific production emails have the admin role (idempotent)
|
||||
$adminEmails = [
|
||||
'klara@resovision.com',
|
||||
];
|
||||
|
||||
$adminUserIds = User::whereIn('email', $adminEmails)->pluck('id');
|
||||
if ($adminUserIds->isNotEmpty()) {
|
||||
// Attach without detaching any existing roles
|
||||
$admin->users()->syncWithoutDetaching($adminUserIds->all());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user