Monthly Archives: March 2013

Laravel 4 Pagination with Column Sorting

It took a little effort, but I finally got Laravel 4′s pagination class working with the ability to sort by column. Posted here so I don’t forget.


$widgets = Widget::all();
$sort = (!is_null(Input::get('sort')) ? Input::get('sort') : 'name'); 
//with 'name' being the default column to sort on.
$order = (!is_null(Input::get('order')) ? Input::get('order') : 'desc');
//'desc' is the default sort order.
$widgets = $widgets->orderBy($sort, $order);
$widgets = $widgets->paginate(20);

//include $order and $sort when retrieving your layout/view
$this->layout->nest('content', 'widgets.index',array('widgets' => $widgets, 'sort' => $sort, 'order' => $order));

//Display the pagination
//I tried using appends() first, but could not chain multiples
{{ $events->addQuery('order',$order)->addQuery('sort', $sort)->links() }}

//Column header
{{link_to_route('widgets.index','Name', array('sort' => 'name'))}}
//Using Twitter Boostrap up/down arrows
<a href="{{route($route, array('sort' => $sort, 'order' => 'asc'))}}">
        <i class="icon-chevron-up"></i>
<a href="{{route($route, array('sort' => $sort, 'order' => 'desc'))}}">
        <i class="icon-chevron-down"></i>

The scary thing about relying on Composer with Laravel 4

This kind of sums up my concerns about over-reliance on Composer for what some people might consider core functionality in a PHP Framework.

Over 3000 installs on Packagist, and now suddenly, this package for Laravel to replace functionality left out (for now) from Laravel 4 is not being maintained anymore.

An explanation, but not very comforting:

Using Git to display your web app’s version

I’m mainly writing this down for my own benefit, but others might find this useful. In a previous post about setting up git to deploy to a remote web server, I wrote about a way to display the lastest abbreviated commit hash in your web app’s footer.

Today, I discovered that simply running:

git describe

will output the most recent tag and the current abbreviated commit hash (if there are commits after the tag), so you can use tags to show more human-readable versions of your app (v1.0, etc.) along with the current commit. Unfortunately, you apparently can’t run ‘git describe’ on a bare git repository like what I’m using for deployment on the remote server.

Continue reading