30 lines
1.0 KiB
PHP
30 lines
1.0 KiB
PHP
<?php
|
|
|
|
// Run with: php artisan tinker --execute="require base_path('fix_content_manager.php');"
|
|
// Delete this file after use.
|
|
|
|
// For every Admin profile, ensure all AdminRole scoped Spatie roles exist and have correct permissions.
|
|
|
|
$adminRoles = \App\Models\AdminRole::all();
|
|
$admins = \App\Models\Admin::all();
|
|
|
|
foreach ($admins as $admin) {
|
|
echo "Admin #{$admin->id}: {$admin->name}\n";
|
|
|
|
foreach ($adminRoles as $adminRole) {
|
|
$scopedName = 'Admin\\' . $admin->id . '\\' . $adminRole->name;
|
|
|
|
$spatieRole = \Spatie\Permission\Models\Role::firstOrCreate(
|
|
['name' => $scopedName, 'guard_name' => 'web']
|
|
);
|
|
|
|
$wasCreated = $spatieRole->wasRecentlyCreated;
|
|
$spatieRole->syncPermissions($adminRole->permissions ?? []);
|
|
|
|
echo ' ' . ($wasCreated ? '[CREATED] ' : '[synced] ') . $scopedName . "\n";
|
|
}
|
|
}
|
|
|
|
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
|
echo "\nAll scoped roles ensured and permissions synced. Cache cleared.\n";
|