Hello Devs, 

In this tutorial, we will learn How to Get Current Month Records In Laravel

Follow this step-by-step guide below. 


Example :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = DB::table('users')
                    ->whereYear('created_at', Carbon::now()->year)
                    ->whereMonth('created_at', Carbon::now()->month)
                    ->get();

    dd($users);
}


Output :

Illuminate\Support\Collection {#481 ?
  #items: array:2 [?
    0 => {#491 ?
      +"id": 5
      +"name": "mehul"
      +"email": "bagadamehul@gmail.com"
      +"password": "$2y$10$XN.v3ObOT/1X3XuLKvTPAOGpXMEUAb6hevPL5rYwSZ34IiOEk5N5G"
      +"created_at": "2020-09-09 00:00:00"
      +"updated_at": "2020-09-09 00:00:00"
    }
    1 => {#493 ?
      +"id": 6
      +"name": "keval"
      +"email": "keval@gmial.com"
      +"password": "$2y$10$XN.v3ObOT/1X3XuLKvTPAOGpXMEUAb6hevPL5rYwSZ34IiOEk5N5G"
      +"created_at": "2020-09-16 00:00:00"
      +"updated_at": "2020-09-16 00:00:00"
    }
  ]
}


May this example help you.