mirror of
https://gitee.com/hzchunfen/erp.git
synced 2025-11-30 22:20:45 +00:00
feat: #20220801 新增角色权限
This commit is contained in:
parent
d700f50caa
commit
4800655ba0
@ -16,8 +16,9 @@
|
||||
2. `cp .env.example .env`
|
||||
3. 修改 .env 配置项为本地配置
|
||||
4. 创建数据库 `CREATE DATABASE IF NOT EXISTS `erp` DEFAULT CHARACTER SET utf8;`
|
||||
5. `php artisan migrate`
|
||||
5. `php artisan migrate` 如果数据填充没有执行成功,则需要再次执行 `php artisan migrate:fresh --seed`
|
||||
6. `php artisan key:generate`
|
||||
7. `php artisan update:super_admin_permissions` 更新超级管理员角色权限
|
||||
|
||||
#### 使用说明
|
||||
|
||||
|
||||
47
app/Console/Commands/UpdateSuperPermissions.php
Normal file
47
app/Console/Commands/UpdateSuperPermissions.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
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()
|
||||
{
|
||||
$role = Role::query()->where('name', '超级管理员')->find(1);
|
||||
$permissions = Permission::query()->get();
|
||||
$role->syncPermissions($permissions);
|
||||
$this->info('更新成功');
|
||||
}
|
||||
}
|
||||
@ -12,6 +12,11 @@ use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class GoodsSkusController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware(['role:super-admin','permission:publish articles|edit articles']);
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
return new GoodsSkuResource(GoodsSku::query()->get(['id', 'title']));
|
||||
|
||||
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use App\Http\Resources\RolesResource;
|
||||
|
||||
@ -35,6 +36,15 @@ class RolesController extends Controller
|
||||
return response($this->res, $this->res['httpCode']);
|
||||
}
|
||||
|
||||
public function addPermissions($id, Request $request)
|
||||
{
|
||||
$role = Role::query()->findOrFail($id);
|
||||
$permissions = Permission::query()->findOrFail($request->permissionIds);
|
||||
$role->syncPermissions($permissions);
|
||||
|
||||
return response($this->res, $this->res['httpCode']);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return new RolesResource(Role::query()->find($id));
|
||||
|
||||
@ -61,6 +61,8 @@ class Kernel extends HttpKernel
|
||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
|
||||
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -29,6 +29,7 @@ Route::middleware('auth:api')->group(function () {
|
||||
Route::resource('shops', 'Shop\ShopsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
|
||||
// 角色
|
||||
Route::resource('roles', 'Role\RolesController', ['only' => ['index', 'store', 'show', 'update']]);
|
||||
Route::post('roles/{id}/permissions', 'Role\RolesController@addPermissions');
|
||||
// 权限
|
||||
Route::resource('permissions', 'Permission\PermissionsController', ['only' => ['index', 'store', 'show', 'update', 'destroy']]);
|
||||
// 菜单
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user