Posted By

CreativePunch on 01/04/14


Tagged

css php html programming webdev Coding laravel


Versions (?)

Sortable index view tables with Laravel 4


 / Published in: PHP
 

URL: http://creative-punch.net/2014/01/sortable-index-view-laravel-4/

In this article I would like to share how to make a sortable index view with Laravel 4.

Let’s assume you have an index view with a table. Like this example for a table that contains posts.

  1. public function index()
  2. {
  3. $sortby = Input::get('sortby');
  4. $order = Input::get('order');
  5.  
  6. if ($sortby && $order) {
  7. $posts = $this->post->orderBy($sortby, $order)->get();
  8. } else {
  9. $posts = $this->post->get();
  10. }
  11.  
  12. return View::make('posts.index', compact('posts', 'sortby', 'order'));
  13. }

Report this snippet  

You need to login to post a comment.