How to get last year records count with month wise in Laravel

You can get last year records count with month name in Laravel. You can use DB::raw with Laravel eloquent to get the records count created in specific month with month name.

Answers 1
  • Fetch month wise last year data

    $users = App\Models\User::select(DB::raw("(COUNT(*)) as count"),DB::raw("MONTHNAME(created_at) as monthname"))
     ->whereYear('created_at', date('Y', strtotime('-1 year')))
     ->groupBy('monthname')
     ->get();
    
    0

    This code snippet will help you to get the last year data with month wise.

  • Back to code snippet queries related laravel