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

rudexpunx's avatar

Access validated values in nested array validation

When validating update request for a model, I often use form request and access object being update like $this->route('attribute');

So validating unique attribute looks like this:

public function rules()
    {
        return [
            'name' => 'required|string|unique:attributes,name,' . $this->attribute()->id . ',id'           
        ];
    }

    protected function attribute(): Attribute
    {
        return $this->route('attribute');
    }

but what if I need to validate nested array values (for relationship for example):

public function rules()
    {
        return [
            'name' => 'required|string|unique:attributes,name,' . $this->attribute()->id . ',id' ,
            'values' => 'array',
               'values.*.id' => 'required|numeric|unique:values,id,' . $id_being_validated . ',id'          
        ];
    }

How do I get $id_being_validated?

Thank you for your help!

0 likes
1 reply
rudexpunx's avatar

Any idea? I still haven't found anything convenient... Seems like common use case though.

Please or to participate in this conversation.