Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

234
Views
Datatable order by Month and Year

Can i set datatable order by Month and Year ( where i get the data as "October 2021",...."February 2022" ). Refer the attached image for details

This is my code in controller where i get data .

 $fiveexpdata = Dairyexpense::select(DB::raw('DATE_FORMAT(expensesdate, "%M %Y") as "month_name",SUM(amount) as "amount"'))
          ->whereBetween('expensesdate', [Carbon::now()->subMonth(6),Carbon::now()->endOfMonth()])
          ->groupBy('month_name')
          ->get()
          ->toArray();

After Sending the same in datatable, it shows data in Oct 2021 Nov 2021 Dec 2021 Jan 2022 Feb 2022 March 2022

Where as i required the same in March 2022 Feb 2022 Jan 2022 Dec 2021 Nov 2021 Oct 2021

enter image description here

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Just like said in this :

Group by month and order the dates on Laravel Eloquent

Do you try do add that ?

  ->DB::raw('max(expensesdate) as expensesdate')
  ->orderBy('expensesdate', 'desc')
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!