ProductRequest.php
1.6 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
<?php
namespace App\Http\Requests\Bside\Product;
use App\Enums\Common\Code;
use App\Exceptions\BsideGlobalException;
use App\Helper\Arr;
use App\Models\Product\Product;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
/**
* Class ProductRequest
* @package App\Http\Requests\Bside\product
* @author zbj
* @date 2023/4/12
*/
class ProductRequest 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()
{
return [
'title' => 'required|max:200',
'route' => 'required|max:200',
'seo_mate.keywords' => 'max:300',
'seo_mate.description' => 'max:200',
'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
];
}
public function messages()
{
return [
'title.required' => '请输入产品标题',
'title.max' => '产品标题不能超过200个字符',
'route.required' => '请输入产品链接',
'route.max' => '产品链接不能超过200个字符',
'status.required' => '请选择产品状态',
'status.in' => '产品状态值异常',
// 可选的 seo_mate 子字段的提示
'seo_mate.keywords.max' => 'SEO 关键字不能超过200个字符',
'seo_mate.description.max' => 'SEO 描述不能超过200个字符',
];
}
}