Support the ongoing development of Laravel.io →
Cache Database Eloquent
Last updated 1 year ago.
0

Hello, I don't deal with cache, but I'm quite good in dealing with databases.
{{ count($expedition->subject) }} is really a bad solution, because $expedition->subject retrieves all the subjects, and count() counts them afterwards. Instead you should ask the database to count that subjects.

{{ $expedition->subjects->count() }}

This is in case that the relations name is 'subjects' instead of 'subject'. I can help you with eager loading, if you need.

Last updated 1 year ago.
0
Solution

@Firtzberg - Thanks for the reply. I actually found the solution here: http://laravel.io/forum/05-03-2014-eloquent-get-count-relation

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

rbruhn rbruhn Joined 16 Apr 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.