I would now recover my articles with an archive system ( list ) year and month with Laravel 4.2 .
I manage to retrieve my items per year and per month with no problem (see below)
Here is my controller using the Query builder Laravel
public function index(){
$post_links = DB::table('posts')
->select(DB::raw('YEAR(created_at) year, MONTH(created_at) month, MONTHNAME(created_at) month_name, COUNT(*) post_count'))
->groupBy('year')
->groupBy('month')
->orderBy('year', 'desc')
->orderBy('month', 'desc')
->get();
return View::make('home.index')->with(array(
'post_links'=>$post_links,
));
}
And my view
<ul id="show-year">
@foreach($post_links as $link)
{{--{{dd($link)}}--}}
{{--Show year--}}
<li>
<a title="" href="#">
<span>
<strong>{{$link->year}}</strong></a> <span class="post-count">{{$link->post_count}}</span><i class="fa fa-arrow-right"></i>
</span>
</li>
</a>
{{--show month--}}
<ul id="show-month">
<li class="month-content">
<a href="">
<span>
<strong>{{$link->month_name}}</strong>
</span>
</a>
</li>
</ul>
</li>
@endforeach
</ul>
I recovered my data years and months but it adds a year each month to her together in this way
2015 ( 21) - May ( 2) - April (3) - March ( 5) - February (1) - January (10) 2016 (10) - December (6) - November (4)
I don't understand why it does not group me in the same year and generates me every time a new entry of year for each month.
Thanks for your help.