Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

First things first, have you dd($show->versions) to see if it does contain any data?

Last updated 2 years ago.
0

I already did that. And it contains data. That's what's puzzling.

Last updated 2 years ago.
0

and the dd says that $show->versions is a collection ?

Last updated 2 years ago.
0

Sorry, I'd done a var_dump. A dd gives me:

 string(1) "1"
Last updated 2 years ago.
0

Any ideas?

Last updated 2 years ago.
0

Hello. I can't find the error, but I have some tips.
Don't use count($show->versions). count is intended for arrays, not collection. I think count($show->versions) allways returns 1. Use $collection->count() instead.
Make dd($show);
Remove all other eager loaded things to see if it helps (probably not).
Eager loading reduces the number of queries made to the database. This increases performaces. But, if you eager load relations of only one entity, that doesn't reduce the number of queries. Eager loading queries each relation seperate. So, actually, you could remove all that eager loading and if you need something you will get it with a simple $model->relation;

Last updated 2 years ago.
0

Thanks, Firtzberg.

Well I'm loading those results on their own, not eager loading, and it works just fine.

What would be the reason for that?

Last updated 2 years ago.
0

Your dd says it is not a collection.

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.

© 2024 Laravel.io - All rights reserved.