Seems odd. Why do you need to do this?
Apr 13, 2020
5
Level 1
Unset attributes after success validation
I'm using Form Request Validation and I want some attributes to be unset after a success validation. I know I should do something in withValidator method and I know there's a removeAttribute method for this but I don't know how to use it.
Here is what I tried:
/**
* Configure the validator instance.
*
* @param \Illuminate\Validation\Validator $validator
* @return void
*/
public function withValidator($validator)
{
$validator->removeAttribute('image');
}
And what I get:
Method Illuminate\Validation\Validator::removeAttribute does not exist.
Level 29
You can override the validated method in your FormRequest
public function validated()
{
$data = $this->validator->validated();
unset($data['images']);
return $data;
}
and then use $request->validated() in your controller
Please or to participate in this conversation.