Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ehsanm's avatar

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.
0 likes
5 replies
Snapey's avatar

Seems odd. Why do you need to do this?

ehsanm's avatar

Because I have a separate table for images and I don't want to store image value in related model's table.

Snapey's avatar

Well just don't write that value to the database ! You can use $request->only() to specify the fields to save or $request->except() to specify fields you dont want

wingly's avatar
wingly
Best Answer
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.