I got an input that contains an array of objects. Now I'd like to validate it, but one part of the validation depends on another item of the object, so I need it's index:
[
'items.myarray.*.owner_id' => 'numeric|exists:App\Models\Owner',
'items.myarray.*.key' => ['nullable', 'string', 'min:20', 'max:20', 'exists:App\Models\Invitation,key',
new KeyIsValid(Owner::findOrFail(request()->input('items.*.owner_id')))],
];
Of course request()->input('items.myarray.*.owner_id') is not working - but I am looking for a way to pass the owner_id of the current object to this validation.
This will return an array value Try to use
$request()->input('items.myarray.*.key')[0]
it will return a string value of "items.myarray.*.key" and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With