12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php namespace App\Http\Requests\Api;
- use App\Http\Requests\BaseRequest;
- /**
- * 地址验证器
- *
- */
- class CustomAddr extends BaseRequest
- {
- /**
- * 获取应用于请求的规则
- *
- * @return array
- */
- public function rules()
- {
- // 编辑时排除ID
- // 返回结果
- return [
- // 有时候我们希望某个字段在第一次验证失败后就停止运行验证规则,只需要将 bail 添加到规则中:
- // 验证字段,验证规则,提示信息
- // 地址
- 'id' => 'required|integer|gt:0',
- 'contact_province' => 'required|max:10',
- 'contact_city' => 'required|max:10',
- 'contact_area' => 'required|max:10',
- 'contact_addr' => 'required|max:64',
- // 备注
- 'contact_name' => 'required|max:20',
- 'contact_phone' => 'required|phone',
- ];
- }
- // 场景列表
- protected $scenes = [
- 'add' => ['contact_province','contact_city','contact_area','contact_name','contact_phone'],
- 'edit' => ['id','contact_province','contact_city','contact_area','contact_name','contact_phone'],
- 'del' => ['id'],
- 'set_default' => ['id'],
- ];
- /**
- * 获取已定义验证规则的错误消息
- *
- * @return array
- */
- public function messages()
- {
- return [
- 'contact_province.required' => '请选择地区',
- 'contact_city.required' => '请选择地区',
- 'contact_area.required' => '请选择地区',
- 'contact_addr.required' => '请填写地址',
- 'contact_province.max' => '省份超长啦',
- 'contact_city.max' => '城市超长啦',
- 'contact_area.max' => '区县超长啦',
- 'contact_addr.max' => '地址超长啦',
- 'contact_name.required' => '请填写收件人',
- 'contact_phone.required' => '请填写收件人手机号',
- 'contact_phone.phone' => '请填写正确的手机号',
- 'id.required' => '请选择地址',
- 'id.integer' => '地址格式有误',
- 'id.gt' => '地址格式有误',
- ];
- }
- }
|