|
...
|
...
|
@@ -2,6 +2,9 @@ |
|
|
|
|
|
|
|
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\Validation\Rule;
|
|
...
|
...
|
@@ -32,18 +35,48 @@ class ProductRequest extends FormRequest |
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'title'=>'required|max:200',
|
|
|
|
'route'=>'required|max:100',
|
|
|
|
'gallery'=>'required|array',
|
|
|
|
'attrs'=>'required|array',
|
|
|
|
'category_id'=>'required',
|
|
|
|
'keywords'=>'required',
|
|
|
|
'intro'=>'required|max:500',
|
|
|
|
'content'=>'required',
|
|
|
|
'describe'=>'required|array',
|
|
|
|
'seo_mate'=>'required|array',
|
|
|
|
'related_product_id'=>'required',
|
|
|
|
'status'=>['required', Rule::in(array_keys(Product::statusMap()))],
|
|
|
|
'title' => 'required|max:200',
|
|
|
|
'route' => 'required|max:100',
|
|
|
|
'gallery' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
foreach ($value as $v) {
|
|
|
|
if (empty($v['url'])) {
|
|
|
|
$fail('图片链接不能为空');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
'attrs' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
foreach ($value as $v) {
|
|
|
|
if (empty($v['key'])) {
|
|
|
|
$fail('产品属性名不能为空');
|
|
|
|
}
|
|
|
|
if (empty($v['value'])) {
|
|
|
|
$fail('产品属性值不能为空');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
'category_id' => 'required',
|
|
|
|
'keywords' => 'required',
|
|
|
|
'intro' => 'required|max:500',
|
|
|
|
'content' => 'required',
|
|
|
|
'describe' => 'required|array',
|
|
|
|
'seo_mate' => ['required', 'array', function ($attribute, $value, $fail) {
|
|
|
|
if(empty($value['title'])){
|
|
|
|
$fail('SEO标题不能为空');
|
|
|
|
}
|
|
|
|
if(empty($value['description'])){
|
|
|
|
$fail('SEO描述不能为空');
|
|
|
|
}
|
|
|
|
if(empty($value['keyword'])){
|
|
|
|
$fail('SEO关键词不能为空');
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
'related_product_id' => ['required', function ($attribute, $value, $fail) {
|
|
|
|
$value = array_filter(Arr::splitFilterToArray($value), 'intval');
|
|
|
|
if(count($value) > 16){
|
|
|
|
$fail('关联产品不能超过16个');
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
'status' => ['required', Rule::in(array_keys(Product::statusMap()))],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|