php - How to get the latest request in model Laravel?

811

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????

People are also looking for solutions to the problem: jquery - Assign post values of multiple checkbox inputs to a PHP variable and separate by comma

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.