|
@@ -2,6 +2,9 @@ |
|
@@ -2,6 +2,9 @@ |
|
2
|
|
2
|
|
|
3
|
namespace App\Http\Requests\Bside\product;
|
3
|
namespace App\Http\Requests\Bside\product;
|
|
4
|
|
4
|
|
|
|
|
5
|
+use App\Enums\Common\Code;
|
|
|
|
6
|
+use App\Exceptions\BsideGlobalException;
|
|
|
|
7
|
+use App\Helper\Arr;
|
|
5
|
use App\Models\Product\Product;
|
8
|
use App\Models\Product\Product;
|
|
6
|
use Illuminate\Foundation\Http\FormRequest;
|
9
|
use Illuminate\Foundation\Http\FormRequest;
|
|
7
|
use Illuminate\Validation\Rule;
|
10
|
use Illuminate\Validation\Rule;
|
|
@@ -32,18 +35,48 @@ class ProductRequest extends FormRequest |
|
@@ -32,18 +35,48 @@ class ProductRequest extends FormRequest |
|
32
|
public function rules()
|
35
|
public function rules()
|
|
33
|
{
|
36
|
{
|
|
34
|
return [
|
37
|
return [
|
|
35
|
- 'title'=>'required|max:200',
|
|
|
|
36
|
- 'route'=>'required|max:100',
|
|
|
|
37
|
- 'gallery'=>'required|array',
|
|
|
|
38
|
- 'attrs'=>'required|array',
|
|
|
|
39
|
- 'category_id'=>'required',
|
|
|
|
40
|
- 'keywords'=>'required',
|
|
|
|
41
|
- 'intro'=>'required|max:500',
|
|
|
|
42
|
- 'content'=>'required',
|
|
|
|
43
|
- 'describe'=>'required|array',
|
|
|
|
44
|
- 'seo_mate'=>'required|array',
|
|
|
|
45
|
- 'related_product_id'=>'required',
|
|
|
|
46
|
- 'status'=>['required', Rule::in(array_keys(Product::statusMap()))],
|
38
|
+ 'title' => 'required|max:200',
|
|
|
|
39
|
+ 'route' => 'required|max:100',
|
|
|
|
40
|
+ 'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
41
|
+ foreach ($value as $v) {
|
|
|
|
42
|
+ if (empty($v['url'])) {
|
|
|
|
43
|
+ $fail('图片链接不能为空');
|
|
|
|
44
|
+ }
|
|
|
|
45
|
+ }
|
|
|
|
46
|
+ }],
|
|
|
|
47
|
+ 'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
48
|
+ foreach ($value as $v) {
|
|
|
|
49
|
+ if (empty($v['key'])) {
|
|
|
|
50
|
+ $fail('产品属性名不能为空');
|
|
|
|
51
|
+ }
|
|
|
|
52
|
+ if (empty($v['value'])) {
|
|
|
|
53
|
+ $fail('产品属性值不能为空');
|
|
|
|
54
|
+ }
|
|
|
|
55
|
+ }
|
|
|
|
56
|
+ }],
|
|
|
|
57
|
+ 'category_id' => 'required',
|
|
|
|
58
|
+ 'keywords' => 'required',
|
|
|
|
59
|
+ 'intro' => 'required|max:500',
|
|
|
|
60
|
+ 'content' => 'required',
|
|
|
|
61
|
+ 'describe' => 'required|array',
|
|
|
|
62
|
+ 'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
63
|
+ if(empty($value['title'])){
|
|
|
|
64
|
+ $fail('SEO标题不能为空');
|
|
|
|
65
|
+ }
|
|
|
|
66
|
+ if(empty($value['description'])){
|
|
|
|
67
|
+ $fail('SEO描述不能为空');
|
|
|
|
68
|
+ }
|
|
|
|
69
|
+ if(empty($value['keyword'])){
|
|
|
|
70
|
+ $fail('SEO关键词不能为空');
|
|
|
|
71
|
+ }
|
|
|
|
72
|
+ }],
|
|
|
|
73
|
+ 'related_product_id' => ['required', function ($attribute, $value, $fail) {
|
|
|
|
74
|
+ $value = array_filter(Arr::splitFilterToArray($value), 'intval');
|
|
|
|
75
|
+ if(count($value) > 16){
|
|
|
|
76
|
+ $fail('关联产品不能超过16个');
|
|
|
|
77
|
+ }
|
|
|
|
78
|
+ }],
|
|
|
|
79
|
+ 'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
|
|
47
|
];
|
80
|
];
|
|
48
|
}
|
81
|
}
|
|
49
|
|
82
|
|