php - Laravel 5.1 Modify input before form request validation -


is there way modify input fields inside form request class before validation takes place?

i want modify input date fields follows doesn't seem work.

when set $this->start_dt input field 2016-02-06 12:00:00 , $this->end_dt 2016-02-06 13:00:00 still validation error "end_dt must after start_dt". means input request values aren't getting changed when update $this->start_dt , $this->end_dt inside rules() function.

public function rules() {     if ($this->start_dt){         $this->start_dt = carbon::createfromformat('d m y h:i:s', $this->start_dt . ' ' . $this->start_hr . ':'. $this->start_min . ':00');     }      if ($this->end_dt){         $this->end_dt = carbon::createfromformat('d m y h:i:s', $this->end_dt . ' ' . $this->end_hr . ':'. $this->end_min . ':00');     }      return [         'start_dt' => 'required|date|after:yesterday',         'end_dt' => 'required|date|after:start_dt|before:' . carbon::parse($this->start_dt)->adddays(30)                 ]; } 

note: start_dt , end_dt date picker fields , start_hr, start_min drop down fields. hence need create datetime combining fields can compare.

as of laravel 5.4 can override prepareforvalidation method of validateswhenresolvedtrait modify input. similar should possible laravel 5.1.

example in request

/**  * modify input values  *  * @return void  */ protected function prepareforvalidation() {      // input     $input = array_map('trim', $this->all());      // check newsletter     if (!isset($input['newsletter'])) {         $input['newsletter'] = false;     }      // replace old input new input     $this->replace($input); } 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -