How to sort records in alphabetical order in laravel?
public function index()
{
$comproducts = Comproduct::paginate(3);
$items = Item::orderBy('name')->all();
return view('computer', compact(['comproducts', 'items']));
}
This is not working correctly. This shows
Call to undefined method Illuminate\Database\Query\Builder::all()
this error. How can i fix this?
I use
get()
instead , you can't modify query with methodall()
and also it is static functionThat's how you sort it,
orderBy()
comes afterall()
:Reference: https://laravel.com/docs/5.5/collections
Hi Please find an answer based on eloquent query laravel
Table: Users Columns:id,name,class_id