How To Get Month Name From Date In Laravel

In this tutorial i will show you how to get month name from date in laravel. To get month name not month value. We will print month name like September for value 9 and October for month value 10. You will learn how to convert month number to month name in laravel.

I also show how to get all month name in laravel from controller. So if you don't the how to write the query of get all month name in mysql  in laravel, then follow the below example to get month name in laravel. 

Example code : 

return User::selectRaw('year(created_at) as year, monthname(created_at) as month, count(*) as published')
           ->groupBy('year','month')
           ->orderByRaw('min(created_at) desc')
           ->get();

 

or simply use this to get month name from date in laravel

$monthname = date('F', strtotime($user->created_at)); 

 

Read also : How to get only year, month and day from timestamp in Laravel

 

Hope it can help you.

 

#laravel #eloquent-tips #laravel-7x