Modify input before validation on Laravel 5.1

后端 未结 5 1824
故里飘歌
故里飘歌 2021-01-07 22:17

I\'m trying to modify an user submitted input before validation success. I\'ve followed this easy instructions, but when I test it on Laravel 5.1, It\'s not working.

5条回答
  •  孤城傲影
    2021-01-07 22:50

    These answers no longer work for me in 5.5

    you can use

    protected function validationData()
    {
        $this->request->add([
            'SomeField' => '..some code to modify it goes here'
        ]);
        return $this->request->all();
    }
    

    the add method on request overwrites any existing input for that key.

    You can see why this works in Illuminate\Foundation\Http\FormRequest, if you follow the trail

    /**
     * Get data to be validated from the request.
     *
     * @return array
     */
    protected function validationData()
    {
        return $this->all();
    }
    

提交回复
热议问题