How to select year and month from the created_at attributes of database table in laravel 5.1?
There are date helpers available in the query builder:
$post = Mjblog::whereYear('created_at', '=', $year)
->whereMonth('created_at', '=', $month)
->get();
If you want to get the year and month from a single instance of Mjblog
you can access them like this:
$year = $post->created_at->year;
$month = $post->created_at->month;
Read more about Carbon\Carbon
getters documentation.