I have a table with 10 different fields. I want to be able to click the column of the table then the page will reload with the order by in the column that was selected.
I've added this to my routes:
Route::get('/inventory/sort/{sortby}', ['uses' => 'ItemController@index']);
My Controller:
public function index($sortby = null) {
$Inventory_Items = ItemDynamic::with(['Item'])
->orderBy(function ($query) use($sortby) {
if ($sortby == "quantity") {
$query->orderBy('Quantity','asc');
} else if ($sortby == 'name') {
$query->orderBy('name','asc');
} else {
$query->orderBy('id','asc');
}
})
->paginate(20);
return view('adminlte::Item.index', ['Inventory_Items' => $Inventory_Items]);
}
So, when I access /inventory/sort/quantity
it should result in a order by quantity.
Instead, I get a strtolower() error.
Any ideas on how to accomplish this?