mirror of
https://gitee.com/ctexthuang/hyperf_rbac_framework_server_ctexthuang.git
synced 2025-12-25 22:47:50 +08:00
80 lines
1.7 KiB
PHP
80 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Request\Admin;
|
|
|
|
use App\Common\Trait\HttpMethodTrait;
|
|
use Hyperf\Validation\Request\FormRequest;
|
|
|
|
class AdminRoleRequest extends FormRequest
|
|
{
|
|
use HttpMethodTrait;
|
|
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*/
|
|
public function authorize(): bool
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [
|
|
'name' => 'required|string|max:60',
|
|
'code' => [
|
|
'required',
|
|
'string',
|
|
'max:60',
|
|
'regex:/^[a-zA-Z0-9_]+$/',
|
|
],
|
|
'status' => 'sometimes|integer|in:1,2',
|
|
'sort' => 'required|integer',
|
|
'remark' => 'nullable|string|max:255',
|
|
'permissions' => 'sometimes|array',
|
|
'permissions.*' => 'string|exists:admin_menu,name',
|
|
];
|
|
if ($this->isCreate()) {
|
|
$rules['code'][] = 'unique:admin_role,code';
|
|
}
|
|
if ($this->isUpdate()) {
|
|
$rules['code'][] = 'unique:admin_role,code,' . $this->route('id');
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return parent::messages();
|
|
}
|
|
|
|
protected array $scenes = [
|
|
'update' => [
|
|
'code',
|
|
'name',
|
|
'status',
|
|
'sort',
|
|
'remark',
|
|
],
|
|
'create' => [
|
|
'code',
|
|
'name',
|
|
'status',
|
|
'sort',
|
|
'remark',
|
|
],
|
|
'batch_grant_permission' => [
|
|
'permissions',
|
|
'permissions.*',
|
|
]
|
|
];
|
|
}
|