1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/4/10 0010
- * Time: 13:07
- */
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Contracts\Validation\Validator;
- use Illuminate\Validation\ValidationException;
- use Symfony\Component\HttpFoundation\Response;
- class Request extends FormRequest
- {
- protected function failedValidation(Validator $validator)
- {
- $messageList = [];
- foreach ($validator->errors()->messages() as $items) {
- foreach ($items as $item) {
- $messageList[] = $item;
- }
- }
- $message = implode('<br>', $messageList);
- $format = json_encode(['message' => $message]);
- throw (new ValidationException($validator, new Response($format, 422)))
- ->errorBag($this->errorBag)
- ->redirectTo($this->getRedirectUrl());
- }
- // public function messages()
- // {
- // return [
- // 'required' => ':attribute不能为空',
- // 'in' => ':attribute必须是以下取值: :values',
- // 'numeric' => ':attribute必须是数字',
- // 'max' => [
- // 'numeric' => ':attribute 应小于:max ',
- // 'file' => ':attribute 应小于:max kb',
- // 'string' => ':attribute应小于 :min 位',
- // 'array' => ':attribute应大于 :min 列表',
- // ],
- // 'min' => [
- // 'numeric' => ':attribute应大于 :min ',
- // 'file' => ':attribute应大于 :min kb',
- // 'string' => ':attribute应大于 :min 位',
- // 'array' => ':attribute应大于 :min 列表',
- // ],
- // 'unique' => ':attribute 已存在',
- // 'array' => ':attribute应为列表'
- // ];
- // }
- }
|