How to sort records in alphabetical order in Laravel

I use get() instead , you can't modify query with method all() and also it is static function

  $items = Item::orderBy('name')->get(); 

That's how you sort it, orderBy() comes after all():

$items = Item::all()->sortBy('name');    

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

$users = DB::table('users')->whereIn('class_id', [1, 2, 3])->orderBy('name', 'ASC')->paginate(50);

Tags:

Php

Laravel

Blade