CustomRequest.php
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
namespace App\Http\Requests\Bside\Custom;
use Illuminate\Foundation\Http\FormRequest;
/**
* @author:dc
* @time 2023/5/12 9:45
* Class CustomRequest
* @package App\Http\Requests\Bside\Custom
*/
class CustomRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
$rule = [
'name' => ['required','max:100'],
'title' => [],//'required','max:200'
'keywords' => [],//'required','max:200'
'description' => [],//'required','max:250'
// 'html' => ['required'],
'url' => ['required','max:200'],
'status' => ['required','in:0,1'],
];
// 修改
if($this->is('b/custom/update')){
$rule['id'] = ['required','integer'];
}
// 删除
if($this->is('b/custom/delete')){
$rule = ['id' => ['required','integer']];
}
return $rule;
}
public function messages()
{
return [
'id.required' => '数据不存在',
'id.integer' => '数据不存在',
'name.required' => '名称必须',
'name.max' => '名称不能超过100个字符',
'title.required' => '网页标题必须',
'title.max' => '网页标题不能超过200个字符',
'keywords.required' => '网页关键字必须',
'keywords.max' => '网页关键字不能超过200个字符',
'description.required' => '网页描述必须',
'description.max' => '网页描述不能超过250个字符',
'url.required' => '链接必须',
'url.max' => '链接不能超过200个字符',
'url.url' => '链接不符合规则',
'status.required' => '状态选择错误',
'status.in' => '状态必须是显示/隐藏'
];
}
}