Sortable index view tables with Laravel 4


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.