Update
parent
a3cd26602f
commit
be80b4bf0c
|
|
@ -17,46 +17,62 @@ class AgriculturalBaseRequest extends FormRequest
|
|||
*/
|
||||
public function rules()
|
||||
{
|
||||
if ($this->input('type') == 2) {
|
||||
return [
|
||||
'type' => ['bail', 'required', new Enum(BaseType::class)],
|
||||
'name' => ['bail', 'required', 'string', 'max:100'],
|
||||
'address' => ['bail', 'required', 'string', 'max:190'],
|
||||
'areas' => ['bail', 'required', 'numeric', 'min:0', 'max:9999999999.99', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
|
||||
'cultivated' => ['bail', 'required', 'numeric', 'min:0', 'max:9999999999.99', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
|
||||
'workforce' => ['bail', 'required', 'int', 'min:0', 'max:2147483647'],
|
||||
'description' => ['bail', 'nullable', 'string'],
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => ['required', new Enum(BaseType::class)],
|
||||
'name' => 'required|string|max:100',
|
||||
'description' => 'nullable|string',
|
||||
'person' => 'required_if:type,1|string|max:100',
|
||||
'crops_ids' => 'nullable|array|min:1',
|
||||
'areas' => 'required|regex:/^\d+(\.\d{1,2})?$/',
|
||||
'workforce' => 'required|integer|min:0',
|
||||
'address' => 'nullable|string',
|
||||
'address_lat' => 'nullable|regex:/^\d+(\.\d{1,10})?$/',
|
||||
'address_lng' => 'nullable|regex:/^\d+(\.\d{1,10})?$/',
|
||||
'parent_id' => 'required_if:type,1|integer|min:0',
|
||||
'sort' => 'nullable|integer|min:0',
|
||||
'type' => ['bail', 'required', new Enum(BaseType::class)],
|
||||
'parent_id' => ['bail', 'required', 'int'],
|
||||
'name' => ['bail', 'required', 'string', 'max:100'],
|
||||
'person' => ['bail', 'required', 'string', 'max:100'],
|
||||
'crops_ids' => ['bail', 'required', 'array'],
|
||||
'areas' => ['bail', 'required', 'numeric', 'min:0', 'max:9999999999.99', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
|
||||
'cultivated' => ['bail', 'required', 'numeric', 'min:0', 'max:9999999999.99', 'regex:/^([1-9]\d*|0)(\.\d{1,2})?$/'],
|
||||
'workforce' => ['bail', 'required', 'int', 'min:0', 'max:2147483647'],
|
||||
'description' => ['bail', 'nullable', 'string'],
|
||||
'address' => ['bail', 'required', 'string', 'max:190'],
|
||||
'address_lat' => ['bail', 'nullable', 'regex:/^\d+(\.\d{1,10})?$/'],
|
||||
'address_lng' => ['bail', 'nullable', 'regex:/^\d+(\.\d{1,10})?$/'],
|
||||
'sort' => ['bail', 'nullable', 'int', 'min:0', 'max:2147483647'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
public function attributes()
|
||||
{
|
||||
$messages = [
|
||||
'type' => '请选择区域类别',
|
||||
'name.required' => '请填写名称',
|
||||
'name.max' => '名称不能超过100字',
|
||||
'description.string' => '请正确填写介绍',
|
||||
'person.required_if' => '请填写负责人名称',
|
||||
'person.max' => '负责人名称不能超过100字',
|
||||
'crops_ids.min' => '至少选择一种农作物',
|
||||
'areas.required' => '请填写面积',
|
||||
'areas.regex' => '请正确填写面积',
|
||||
'workforce.required' => '请填写人数',
|
||||
'workforce.min' => '人数最小为0',
|
||||
'address.string' => '请正确填写地址',
|
||||
'parent_id.required_if' => '请选择城镇',
|
||||
if ($this->input('type') == 2) {
|
||||
return [
|
||||
'name' => '街镇名称',
|
||||
'address' => '街镇地址',
|
||||
'areas' => '街镇面积',
|
||||
'cultivated' => '耕地面积',
|
||||
'workforce' => '街镇人数',
|
||||
'description' => '街镇介绍',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'industry_key' => '农业类型',
|
||||
'name' => '基地名称',
|
||||
'person' => '基地负责人',
|
||||
'areas' => '基地面积',
|
||||
'cultivated' => '种养植面积',
|
||||
'workforce' => '基地人数',
|
||||
'parent_id' => '城镇',
|
||||
'crops_ids' => '基地农作物',
|
||||
'description' => '基地介绍',
|
||||
'address' => '基地地址',
|
||||
'address_lng' => '基地经度',
|
||||
'address_lat' => '基地纬度',
|
||||
'sort' => '排序',
|
||||
];
|
||||
|
||||
return $messages;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
$error = $validator->errors()->all();
|
||||
throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue