Laravel show articles ordered

1

How can I get a quantity of items ordered from the newest to the oldest (currently it appears from the oldest to the newest) in laravel 5.4

in the controller, the function of the home page home is like this:

public function home(){

      $blogs = Blog::paginate(7);

      return view('welcome',[

        'blogs' => $blogs,

      ]);
    
asked by MarianoV 29.08.2017 в 06:39
source

1 answer

2

If the model uses timestamp created_at , then you can sort it down by that field:

$blogs = Blog::orderBy('created_at', 'desc')->paginate(7);

In case you do not use these timestamps, assuming you have an id column that increases automatically, then you could do it like this:

$blogs = Blog::orderBy('id', 'desc')->paginate(7);
    
answered by 29.08.2017 / 06:44
source