The pagination documentation has good info on how to add sorting to the paginated links for your data:
<?php echo $orders->appends(array('sort' => 'name', 'sort_dir'=>'asc'))->links();
to generate links like this:
http://example.com/something?page=2&sort=name&sort_dir=asc
So now you have a table with headers and values and a series of paginated links you can click. Let's say I wanted to change the headers to be clickable links that allowed you to sort by that header. How would I generate that URL?
For example, lets say our current URL is what I said above:
http://example.com/something?page=2&sort=name&sort_dir=asc
And I wanted to click the "NAME" table header in order to change the sorting direction. The URL I would want is:
http://example.com/something?page=2&sort=name&sort_dir=desc
I have a controller called : AdminController.php this is the method used:
public function getAdmins() {
// CACHE SORTING INPUTS
$allowed = array('first_name', 'last_name', 'email', 'activated', 'crated_at'); // add allowable columns to search on
$sort = in_array(Input::get('sort'), $allowed) ? Input::get('sort') : 'first_name'; // if user type in the url a column that doesnt exist app will default to first_name
$order = Input::get('order') === 'asc' ? 'asc' : 'desc'; // default desc
$action = null;
// select all admins Group = 1
$admins = DB::table('users')
->join('users_roles', 'users.id', '=', 'users_roles.user_id')
->where('users_roles.role_id', '=' ,0)
->orderBy($sort, $order)
->paginate($this->perpage);
// check for actions
if (!is_null(Input::get('action')))
{
$action = Input::get('action');
if ($action == "add")
{
$this->layout->content = View::make('admin.admins-add');
}
}
else
{
// get current counter admin counts
$counter = $admins->getFrom();
View::share('counter', $counter);
View::share('sort', $sort);
View::share('order', $order);
// share admin with template
View::share('admins', $admins);
$this->layout->content = View::make('admin.admins');
}
}
1). how could I display the columns headers links in Laravel inside my view page?
Thanks