Commit 5fcdb075 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Fix PermissionSeeder: use correct column names (name not slug, permission_role...

Fix PermissionSeeder: use correct column names (name not slug, permission_role not role_permissions)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 4de529eb
......@@ -133,14 +133,14 @@ public function run(): void
// Insert permissions (idempotent)
$now = now();
foreach ($permissions as $permission) {
$parts = explode('.', $permission);
DB::table('permissions')->updateOrInsert(
['slug' => $permission],
['name' => $permission],
[
'name' => $permission,
'slug' => $permission,
'module' => explode('.', $permission)[0],
'module' => $parts[0],
'action' => $parts[1] ?? $permission,
'created_at' => $now,
'updated_at' => $now,
]
);
}
......@@ -159,14 +159,20 @@ public function run(): void
if ($perms === '*') {
$permIds = DB::table('permissions')->pluck('id')->toArray();
} else {
$permIds = DB::table('permissions')->whereIn('slug', $perms)->pluck('id')->toArray();
$permIds = DB::table('permissions')->whereIn('name', $perms)->pluck('id')->toArray();
}
// Sync: remove old, insert new
DB::table('role_permissions')->where('role_id', $role->id)->delete();
$inserts = array_map(fn ($pid) => ['role_id' => $role->id, 'permission_id' => $pid], $permIds);
DB::table('permission_role')->where('role_id', $role->id)->delete();
$scope = in_array($roleSlug, ['super_admin', 'academy_owner', 'academy_admin']) ? 'all' : 'academy';
$inserts = array_map(fn ($pid) => [
'role_id' => $role->id,
'permission_id' => $pid,
'scope' => $scope,
'created_at' => $now,
], $permIds);
foreach (array_chunk($inserts, 100) as $chunk) {
DB::table('role_permissions')->insert($chunk);
DB::table('permission_role')->insert($chunk);
}
$this->command->info(" Role '{$roleSlug}': " . count($permIds) . ' permissions assigned.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment