erp/app/Console/Commands/UpdateSuperAdminPermissions.php

52 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;
class UpdateSuperAdminPermissions 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()
{
$roleName = '超级管理员';
$role = Role::query()->where('name', $roleName)->find(1);
$permissions = Permission::query()->get();
$role->syncPermissions($permissions);
$user = User::query()->find(1);
$user->assignRole($role);
$this->info('更新成功');
}
}