generated from liutk/owl-admin-base
51 lines
1.3 KiB
PHP
51 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
|
|
class ReceiveGiftRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function rules()
|
|
{
|
|
return [
|
|
'consignee'=> 'required|max:20',
|
|
'phone'=> 'regex:/^1[3456789]\d{9}$/',
|
|
'address'=>'required|max:50',
|
|
];
|
|
}
|
|
|
|
public function messages(){
|
|
$messages = [
|
|
'consignee.required'=>'请填写收件人',
|
|
'consignee.max'=>'收件人名称不能超过20位长度',
|
|
'phone.regex'=>'请输入11位有效手机号',
|
|
'address.required'=>'请填写收货地址',
|
|
'address.max'=>'收货地址不能超过50位长度',
|
|
];
|
|
return $messages;
|
|
}
|
|
|
|
protected function failedValidation(Validator $validator){
|
|
$error = $validator->errors()->all();
|
|
throw new HttpResponseException(response()->json(['data' => [], 'code' => 400, 'message' => $error[0]]));
|
|
}
|
|
}
|