php - How can I sanitize laravel 5.2/5.3 Request Inputs? -


i have myrequest.php class extending app\http\requests\request. want trim() every input before validation because e-mail space after not pass validation.

however sanitize() removed src/illuminate/foundation/http/formrequest.php

  1. create abstract sanitizedrequest class extends usual request class.

  2. yourrequest class should extend sanitizedrequest abstract class.

  3. your sanitizedrequest class overrides request::all() so...

    namespace app\http\requests\forms; use app\http\requests\request;  abstract class sanitizedrequest extends request{      private $clean = false;      public function all(){         return $this->sanitize(parent::all());     }       protected function sanitize(array $inputs){         if($this->clean){ return $inputs; }          foreach($inputs $i => $item){             $inputs[$i] = trim($item);         }          $this->replace($inputs);         $this->clean = true;         return $inputs;     } } 

then normal customrequest, extend sanitizedrequest instead of laravel's request class

    class contactrequest extends sanitizedrequest{         public function authorize(){ return true; }         public function rules(){ return []; }     } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -