Laravel paginate order by

You can use something like this in your controller file.

$transactions = Transaction::orderBy('name')->paginate(10);
return view('index', compact('transactions'));

This should do the trick:

$ondata = DB::table('official_news')->orderBy('created_date', 'desc')->paginate(7);


It will be better if you order it by the id because it is going to be faster from the database.

$posts = Post::orderBy('id', 'desc')->paginate(6);

https://laracasts.com/discuss/channels/laravel/combining-paginate-with-orderby

It works fine for Laravel 5.1.