Return to Snippet

Revision: 65633
at January 4, 2014 03:20 by CreativePunch


Initial Code
public function index()
{
    $sortby = Input::get('sortby');
    $order = Input::get('order');

    if ($sortby && $order) {
        $posts = $this->post->orderBy($sortby, $order)->get();
    } else {
        $posts = $this->post->get();
    }

    return View::make('posts.index', compact('posts', 'sortby', 'order'));
}

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

Initial Description
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.

Initial Title
Sortable index view tables with Laravel 4

Initial Tags
css, php, html

Initial Language
PHP