Eloquent withSum Extra Calculation: SubSelect with Raw Query

preview_player
Показать описание
In this video, I want to show a Laravel Eloquent trick on how to calculate the aggregated data before the aggregation.

Links I've mentioned:

- - - - -
Support the channel by checking out our products:
Рекомендации по теме
Комментарии
Автор

Youtube is marking my comments as spam it seems. The solution is to use the withAggregate function. Check the source code for the withSum method to see how it works. It' is the method called in the background.

intipontt
Автор

I have 4 years of experience in laravel but I didn't use laravel sub query in my project. 🤭 I will implement that anyway this video impressive for me

yashpatel
Автор

When those eloquent functions become too complicated I rather just write SQL. I feel it's easier to write and understand. Most people can read SQL easily.

AlbertCloete
Автор

I searched for this thing for 1 hour, thank you very much

oxunjonrahmonov
Автор

this channel is very complete discussing laravel..but i still stuck in english language..nice video nice course..

AldhiAlbadri
Автор

I used subSelect but my problem is ordering the result or searching the column when it has an alias

spartacusyusuf
Автор

Not the elegant way, but I am using this:

use
use



Order::withSum(['items' => function (Builder $query) {
$query->select(new * (`items`.`price`)) AS totalPrice'));
}], 'totalPrice');

renwar
Автор

thanks for this informatin.
i dont think if we can use subquery for this

fajarsetiawansiagian
Автор

Can anyone help me in this query. That i have posts and views so now i want to show popular day and week when most views comes.

NotBeHaris
Автор

With my limited knowledge of Laravel, wouldn't it work if you included the table prefixed to the columns? Ex: items.quantity * items.price

Appreciate the videos! You always post videos that relate to my current projects and I appreciate that 😊

LostInAutism