laravel eloquent all order by code example

Example 1: laravel order by desc

$posts = Post::orderBy('id', 'DESC')->get();

Example 2: laravel order by

$users = DB::table('users')
         -> orderBy('name', 'desc')
         -> get();

Example 3: laravel eloquent order by alphabetical order

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

Example 4: laravel create model

# The easiest way to create a model instance is using the 
# make:model Artisan command:

php artisan make:model Flight

# If you would like to generate a database migration when you 
# generate the model, you may use the --migration or -m option:

php artisan make:model Flight --migration
php artisan make:model Flight -m

Example 5: laravel get all records order by

$posts = Post::orderBy('created_at', 'desc')->get();

Example 6: laravel get all records order by

$results = Project::orderBy('name')->get();

Tags:

Php Example