I have a list of all the "servers" in my "servers" table returned in my view with pagination. I have been struggling to figure out how to get sorting (asc & desc if possible) and filtering (searching within results) working.
Here is my controller code:
$servers = Server::paginate(5);
return View::make('servers.list')
->with('game', '')
->with('servers', $servers);
Here is my view code for the sorting:
<ul class="nav">
<li class="active"><a href="#"><i class="icon-angle-down"></i>{{ Lang::line('servers.rank')->get() }}</a></li>
<li><a href="#">{{ Lang::line('servers.date')->get() }}</a></li>
<li><a href="#">{{ Lang::line('servers.language')->get() }}</a></li>
<li><a href="#">{{ Lang::line('servers.uptime')->get() }}</a></li>
<li>{{ HTML::link(URL::full() .'?sort=votes', Lang::line('servers.votes')->get()) }} </li>
</ul>
I would like for the sorting to be done via simple anchor links and clicking on Votes or Rank or Date will return data with that sorting. Clicking on the same sorting anchor which is currently selected will reverse the direction of the sort.
I also have a bunch of "filter" options such as categories and integer ranges which when applied would "filter"/search the table and return the results with the same sorting as selected before the filter.
Is all/any of this possible with the pagination class? If not what might be the way I go about this? Not really sure the best way when using laravel.