我的代码:
$filter = Products::select(DB::raw('SUM(price) as `total_price`')
DB::raw('SUM(count) as `total_count`')
DB::raw("DATE_FORMAT(date, '%m/%Y') new_date"),
DB::raw('YEAR(date) year, MONTH(date) month'))
->groupBy('year', 'month')
->get();
$result = [];
$total_price = 0;
$total_count = 0;
$new_date = null;
foreach($filter as $f){
$new_date = $f->new_date;
$total_price = $f->total_price;
$total_count = $f->total_count;
}
*注意:请使用 dd($ f), 它将显示总价,总计数和新日期,但它始终显示最新的
示例:
if i input price and count at 02-08-2018 first
i input price and count at 02-08-2020 second,
i input price and count at 02-08-2016 third,
it will show the latest date which is all the data in 02-08-2020
我想要的是,它会根据最新的提交或输入显示,我们可以通过最新的请求获取,
如果我们查看示例,预期结果应该是 02-08-2016 的所有数据。
任何人都可以帮助我吗????