Spaces:
Running
Running
Download app/Http/Requests/ApiChapterRequest.php from lisatthu35/ewa: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/lisatthu35/ewa/resolve/main/app/Http/Requests/ApiChapterRequest.php
- Command line
-
hf download hf://spaces/lisatthu35/ewa/app/Http/Requests/ApiChapterRequest.php
-
curl -L -o ApiChapterRequest.php https://huggingface.co/spaces/lisatthu35/ewa/resolve/main/app/Http/Requests/ApiChapterRequest.php
1.8 kB
| namespace App\Http\Requests; | |
| use Illuminate\Contracts\Validation\Validator; | |
| use Illuminate\Foundation\Http\FormRequest; | |
| use Illuminate\Http\Exceptions\HttpResponseException; | |
| use Illuminate\Http\Response; | |
| class ApiChapterRequest extends FormRequest | |
| { | |
| private $error_messages = array(); | |
| private $error_mobiles = []; | |
| public function rules() | |
| { | |
| return [ | |
| 'chapter_name'=> 'required' | |
| ]; | |
| } | |
| /** | |
| * Determine if the user is authorized to make this request. | |
| * | |
| * @return bool | |
| */ | |
| public function authorize() | |
| { | |
| return true; | |
| } | |
| protected function prepareForValidation() | |
| { | |
| } | |
| protected function failedValidation(Validator $validator) | |
| { | |
| throw new HttpResponseException( | |
| response()->json([ | |
| 'errors' => $this->error_messages, | |
| 'code' => Response::HTTP_UNPROCESSABLE_ENTITY, | |
| 'message' => "fails", | |
| 'error_mobiles' => $this->error_mobiles | |
| ], Response::HTTP_UNPROCESSABLE_ENTITY) | |
| ); | |
| } | |
| public function withValidator(Validator $validator) | |
| { | |
| $validator->after(function ($validator) { | |
| if ($validator->failed()) { | |
| $this->error_messages = $validator->messages()->getMessages(); | |
| foreach ($this->error_messages as $key => $value) { | |
| $item = [ | |
| 'field' => $key, | |
| 'message' => $value[0] | |
| ]; | |
| array_push($this->error_mobiles, $item); | |
| } | |
| return; | |
| } | |
| }); | |
| } | |
| public function messages() | |
| { | |
| return [ | |
| 'chapter_name.required' => 'Bắt buộc nhập', | |
| ]; | |
| } | |
| } | |