1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?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:15',
- 'contact_city' => 'required|max:15',
- 'contact_area' => 'required|max:15',
- 'contact_addr' => 'required|max:64',
- // 备注
- 'contact_name' => 'required|max:20',
- 'contact_shop' => 'required|max:20',
- 'contact_phone' => 'required|phone',
- ];
- }
- // 场景列表
- protected $scenes = [
- 'add' => ['contact_province','contact_city','contact_area','contact_name','contact_phone','contact_shop'],
- 'edit' => ['id','contact_province','contact_city','contact_area','contact_name','contact_phone','contact_shop'],
- 'del' => ['id'],
- 'set_default' => ['id'],
- 'get_guess_addr' => ['contact_shop'],
- ];
- /**
- * 获取已定义验证规则的错误消息
- *
- * @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_shop.required' => '请填写店铺名称',
- 'contact_shop.max' => '店铺最多20字',
- 'contact_phone.required' => '请填写收件人手机号',
- 'contact_phone.phone' => '请填写正确的手机号',
- 'id.required' => '请选择地址',
- 'id.integer' => '地址格式有误',
- 'id.gt' => '地址格式有误',
- ];
- }
- }
|