Skip to content

Instantly share code, notes, and snippets.

@azimidev
Last active August 8, 2017 19:01
Show Gist options
  • Select an option

  • Save azimidev/21d3a10658f97025e7ee4bf0a5f3a6cd to your computer and use it in GitHub Desktop.

Select an option

Save azimidev/21d3a10658f97025e7ee4bf0a5f3a6cd to your computer and use it in GitHub Desktop.
Laravel most generic sorting tabulate data. It works for every column in database
<?php
/**
* Sorting tabulate data
*
* @param $column
* @param $body
* @return string
*/
function sort_column_by($column, $body)
{
$direction = (request()->get('direction') == 'ASC') ? 'DESC' : 'ASC';
$route = route(request()->route()->getAction()['as'], ['sortBy' => $column, 'direction' => $direction]);
return "<a title=\"Sort by {$column}\" href=\"{$route}\">{$body}</a>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment