This commit is contained in:
parent
c733c82681
commit
ebc81a3363
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Beike\Admin\Http\Controllers;
|
||||
|
||||
use Beike\Admin\Http\Requests\AdminRoleRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Spatie\Permission\Models\Role;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
|
@ -48,7 +49,15 @@ class AdminRoleController extends Controller
|
|||
return view('admin::pages.admin_roles.edit', $data);
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param AdminRoleRequest $request
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function store(AdminRoleRequest $request): array
|
||||
{
|
||||
$adminUser = AdminRoleRepo::createAdminRole($request->toArray());
|
||||
return json_success('保存成功', $adminUser);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
/**
|
||||
* AdminRoleRequest.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-08-12 17:48:08
|
||||
* @modified 2022-08-12 17:48:08
|
||||
*/
|
||||
|
||||
namespace Beike\Admin\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class AdminRoleRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:10',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -25,12 +25,7 @@ class AdminRoleRepo
|
|||
*/
|
||||
public static function createAdminRole($data): Role
|
||||
{
|
||||
$adminRole = new Role([
|
||||
'name' => $data['name'],
|
||||
'guard_name' => 'web_admin',
|
||||
]);
|
||||
$adminRole->save();
|
||||
|
||||
$adminRole = Role::findOrCreate($data['name'], 'web_admin');
|
||||
$permissions = $data['permissions'];
|
||||
self::syncPermissions($adminRole, $permissions);
|
||||
return $adminRole;
|
||||
|
|
@ -78,7 +73,7 @@ class AdminRoleRepo
|
|||
}
|
||||
}
|
||||
if (empty($items)) {
|
||||
throw new \Exception('无效的权限');
|
||||
throw new \Exception('权限不能为空,请选择至少一项');
|
||||
}
|
||||
$adminRole->syncPermissions($items);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ return [
|
|||
'orders_show' => 'Detail',
|
||||
'orders_update' => 'Update',
|
||||
'orders_delete' => 'Delete',
|
||||
'orders_update_status' => 'Update Status',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -17,4 +17,5 @@ return [
|
|||
'orders_show' => '订单详情',
|
||||
'orders_update' => '更新订单',
|
||||
'orders_delete' => '删除订单',
|
||||
'orders_update_status' => '更新状态',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
/**
|
||||
* page.php
|
||||
*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||
* @link http://www.guangdawangluo.com
|
||||
* @author Edward Yang <yangjin@opencart.cn>
|
||||
* @created 2022-08-02 14:22:41
|
||||
* @modified 2022-08-02 14:22:41
|
||||
*/
|
||||
|
||||
return [
|
||||
'pages_index' => '单页列表',
|
||||
'pages_create' => '创建单页',
|
||||
'pages_show' => '单页详情',
|
||||
'pages_update' => '单页编辑',
|
||||
'pages_delete' => '删除单页'
|
||||
];
|
||||
Loading…
Reference in New Issue