File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 44
55use Illuminate \Support \Carbon ;
66use Illuminate \Console \Command ;
7+ use Usermp \LaravelPermission \Models \ExtendedUser ;
78use Usermp \LaravelPermission \Models \Role ;
89use Usermp \LaravelPermission \Models \Permission ;
910use 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}
You can’t perform that action at this time.
0 commit comments