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

You probably have to use joins (and alter this code based on your table, etc.).

$lectures = Lecture::join('lectures_types', 'lectures_types.id_lectures', '=', 'lectures.id')
    ->selectRaw('lectures.*, SUM(lectures_types.numb) as total')
    ->groupBy('lectures.id')
    ->get();
0

THANK YOU MY FRIEND YOU SOLVE MY PROBLEM OF THE DAY! @thomastkim

0

there is another neat trick where you create a relationship.. google it.. and then you can do

ModelONE::with(count)->get();

...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Niiwill niiwill Joined 24 Jun 2015

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.