Skip to content

Commit 7a5749f

Browse files
committed
add
1 parent 8828e5e commit 7a5749f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Commands/GenerateSuperAdmin.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Carbon;
66
use Illuminate\Console\Command;
7+
use Usermp\LaravelPermission\Models\ExtendedUser;
78
use Usermp\LaravelPermission\Models\Role;
89
use Usermp\LaravelPermission\Models\Permission;
910
use Usermp\LaravelPermission\Services\PermissionService;
@@ -23,15 +24,23 @@ public function __construct(PermissionService $permissionService)
2324

2425
public function handle()
2526
{
26-
$permission = Permission::firstOrCreate(['name' => 'Super Admin']);
27+
$userId = $this->argument('UserId');
2728

29+
// Check if the user exists
30+
$user = ExtendedUser::find($userId);
31+
if (!$user) {
32+
$this->error("User with ID {$userId} does not exist.");
33+
return;
34+
}
35+
$permission = Permission::firstOrCreate(['name' => 'Super Admin']);
36+
$user->permissions()->attach($permission->id);
2837
foreach (Role::all() as $role) {
2938
$role->permissions()->attach($permission->id, [
3039
'created_at' => Carbon::now(),
3140
'updated_at' => Carbon::now()
3241
]);
3342
}
3443

35-
$this->info('Super Admin permission assigned to all roles successfully.');
44+
$this->info('Super Admin permission assigned to user and all roles successfully.');
3645
}
3746
}

0 commit comments

Comments
 (0)