php - How to get the latest request in model Laravel?
My Code:
$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;
}
*note : please use dd($f) , it will display total price, total count, and new date but it always the latest ones that shown
example:
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
what i want is, it will show according to the latest submit or input, which we can get by the latest request in form,
if we look at the example, the expected result should be all the data at 02-08-2016 .
Can anyone help me please????