erp/app/Console/Commands/UpdateSuperPermissions.php

52 lines
1.1 KiB
PHP
Raw Normal View History

2022-08-01 05:07:38 +08:00
<?php
namespace App\Console\Commands;
2022-08-04 18:13:00 +08:00
use App\Models\User;
2022-08-01 05:07:38 +08:00
use Illuminate\Console\Command;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class UpdateSuperPermissions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update:super_admin_permissions';
/**
* The console command description.
*
* @var string
*/
protected $description = '更新超级管理员权限';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
2022-08-04 18:13:00 +08:00
$roleName = '超级管理员';
$role = Role::query()->where('name', $roleName)->find(1);
2022-08-01 05:07:38 +08:00
$permissions = Permission::query()->get();
$role->syncPermissions($permissions);
2022-08-04 18:13:00 +08:00
$user = User::query()->find(1);
$user->assignRole($role);
2022-08-01 05:07:38 +08:00
$this->info('更新成功');
}
}