I am trying to dynamically add OrderBy clauses to a query.
What i tried
$sort = Input::get('sort');
"category" => "asc",
"created_at" => "desc",
"email" => "asc",
"title" => "asc"
foreach ($sort as $key => $value) {
echo "->orderBy(\"$key\", \"$value\")";
}
Is there a way to associate multiple orderBy with an existing request? Or a way to link them during query creation?
I am using Bootgrid and trying to use its multi-user capabilities.
Code update
This creates a status code of 500.
$advertisements = DB::table('advertisements')
->get();
foreach ($sort as $key => $value) {
$advertisements->orderBy($key, $value);
}
source
share