Level 75
Why, when you can return results with eloquent.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Maybe an example is better in this case.
$result = Model::with('relation1.relation2.relation3')->get();
What about when you are interested in all of the entries from 'relation3'?
I'm thinking about a macro with the 'Collection' class.
Collection::macro('pluck_deep', function($arg) {
$relations = explode('.', $arg);
for ($i = 0; $i < $count; $i++) {
// ...
}
});
$result->pluck_deep('relation1.relation2.relation3');
Has someone did this before or has any ideas? Thanks.
Please or to participate in this conversation.