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

darwin's avatar
Level 11

Use of $request->only() on sub-arrays

Hello,

I am trying to filter my $request that is returning sub-arrays as well.

I would like to use something along the lines of:

$request->sub-array->only(['item_1', 'item_2']);

It doesn't seem to be working like that. Is it possible in some other way?

Thank you!

0 likes
2 replies
Lthreeo's avatar
Lthreeo
Best Answer
Level 1

Hello Guy

Try this one


$yourCollectionOfSubArr = $request->only(['sub_array.item_1', 'sub_array.item_2']);

You can access to sub item with a dot

2 likes

Please or to participate in this conversation.