79 lines
2.8 KiB
PHP
79 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class SystemConfigRequest extends FormRequest
|
|
{
|
|
/**
|
|
* 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.
|
|
*
|
|
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
$rules = [];
|
|
|
|
if ($this->isMethod('post')) {
|
|
$rules = [
|
|
'group' => 'required|string|max:50',
|
|
'key' => 'required|string|max:100|unique:system_configs,key',
|
|
'value' => 'required',
|
|
'type' => 'required|string|in:text,textarea,number,select,radio,checkbox,switch,image,file,color,date,datetime',
|
|
'label' => 'required|string|max:100',
|
|
'description' => 'nullable|string|max:500',
|
|
'options' => 'nullable|string',
|
|
'rules' => 'nullable|string',
|
|
'sort' => 'nullable|integer|min:0',
|
|
'status' => 'nullable|string|in:active,inactive',
|
|
];
|
|
} elseif ($this->isMethod('put')) {
|
|
$rules = [
|
|
'group' => 'nullable|string|max:50',
|
|
'key' => 'nullable|string|max:100',
|
|
'value' => 'nullable',
|
|
'type' => 'nullable|string|in:text,textarea,number,select,radio,checkbox,switch,image,file,color,date,datetime',
|
|
'label' => 'nullable|string|max:100',
|
|
'description' => 'nullable|string|max:500',
|
|
'options' => 'nullable|string',
|
|
'rules' => 'nullable|string',
|
|
'sort' => 'nullable|integer|min:0',
|
|
'status' => 'nullable|string|in:active,inactive',
|
|
];
|
|
}
|
|
|
|
return $rules;
|
|
}
|
|
|
|
/**
|
|
* Get custom messages for validator errors.
|
|
*/
|
|
public function messages(): array
|
|
{
|
|
return [
|
|
'group.required' => '分组不能为空',
|
|
'group.max' => '分组最多50个字符',
|
|
'key.required' => '配置键不能为空',
|
|
'key.max' => '配置键最多100个字符',
|
|
'key.unique' => '配置键已存在',
|
|
'value.required' => '配置值不能为空',
|
|
'type.required' => '配置类型不能为空',
|
|
'type.in' => '配置类型不支持',
|
|
'label.required' => '配置标签不能为空',
|
|
'label.max' => '配置标签最多100个字符',
|
|
'description.max' => '描述最多500个字符',
|
|
'sort.integer' => '排序必须是整数',
|
|
'sort.min' => '排序不能小于0',
|
|
'status.in' => '状态值不正确',
|
|
];
|
|
}
|
|
} |