Get Current Month Data Query Example In Laravel

Hello devs,

In this get current month data in laravel example tutorial, i will show you that query of how to get get current month data in laravel using carbon. I will use carbon to show you the way of fetching current month data in laravel. If you don't know how to fetch current month data using carbon in laravel then this example is for you.

Let assume we have a date column in our table and we have to fetch current month data from this table. I will show you an eloquent query using carbon to current month data in laravel.

Sometimes we need to show that kind of data to make a report in our application. So Let's see the example query of current month data. I will use whereMonth to fetch current month data in laravel.

Example query:

Route::get('/', function (\Illuminate\Http\Request $request) {

    $data = User::select('*')
            ->whereMonth('date', Carbon::now()->month)
            ->get();

});

 

Read also: Laravel Get Last 12 Months Data Query Example

 

Hope it can help you.

 

#laravel #eloquent-tips