Support the ongoing development of Laravel.io →
Database Eloquent

I need to use a relationship multiple times in the same method. I've broken it into multiple queries so that the relationship is used in different queries. This is required because I need to query the same tables with different parameters to return the results in categories.

But when I do this I get the error "Trying to get property of non-object".

I've done a var_dump and it's returning the results correctly. But when I try to call results from the relationship:

$query2->re_used_relationship->field

It gives me the error.

So, can I use "re_used_relationship" multiple times?

Last updated 2 years ago.
0

i dont know if i understood your problem well, try this

$query2->re_used_relationship->get()->field;
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

jerauf jerauf Joined 16 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.