php - Request validation allways passes on Laravel using Dingo/Api -


i'm using dingo/api package.

controller:

public function register(registeruserrequest $request) {     dd('a'); } 

and example email field required:

<?php namespace app\http\requests;   class registeruserrequest extends request {     /**      * determine if user authorized make request.      *      * @return bool      */     public function authorize()     {         return true;     }      /**      * validation rules apply request.      *      * @return array      */     public function rules()     {         return [             'email' => 'required'         ];     } } 

so send request without email, , still getting "a" response.

i tried extend dingo\api\http\request instead of app\http\request, still same.

according wiki

you must overload failedvalidation , failedauthorization methods. these methods must throw 1 of above mentioned exceptions , not response http exceptions laravel throws.

if take @ dingo\api\http\formrequest.php, you'll see:

class formrequest extends illuminateformrequest {     /**      * handle failed validation attempt.      *      * @param \illuminate\contracts\validation\validator $validator      *      * @return mixed      */     protected function failedvalidation(validator $validator)     {         if ($this->container['request'] instanceof request) {             throw new validationhttpexception($validator->errors());         }          parent::failedvalidation($validator);     }      /**      * handle failed authorization attempt.      *      * @return mixed      */     protected function failedauthorization()     {         if ($this->container['request'] instanceof request) {             throw new httpexception(403);         }          parent::failedauthorization();     } } 

hence, need change names of methods appropriately, , have them throw appropriate exceptions, instead of returning boolean.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -