如何执行Laravel 5 Query

时间:2015-03-20 11:09:22

标签: laravel laravel-5

我是laravel的新手,仍然在开始执行查询。我坚持这个我无法弄清楚的查询。

Models: Flag -> Quote -> QuoteItems

       1 - Quotes has many QuoteItems | QuoteItems has One Quote
       2 - Each Quote has one Flag(e.g accepted, rejected)


1- QuoteItems contains Profit and Price fields.

我需要所有与一个标志相关的引号的SUM(利润)和SUM(价格)。

1 个答案:

答案 0 :(得分:0)

您可以使用以下查询:

// Sum of price
$totalPrice= Quote->groupBy(' Flag')->sum('Price');

// Sum of profit
$totalProfit = Quote->groupBy('Flag')->sum('Profit');

有关详细信息,请转到http://laravel.com/docs/5.0/queries#aggregates