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

Created at 18-Nov-2021 , By samar

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

With this article, we will examine several different instances of how to solve the "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.
  • 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();
    

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

Back to code snippet queries related laravel

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Buy Me A Coffee

Don't forget to share this article! Help us spread the word by clicking the share button below.

We appreciate your support and are committed to providing you valuable and informative content.

We are thankful for your never ending support.