Reverse product list in Laravel

780 Views Asked by At

How can I reverse the product list in Laravel? Below is the code:

public function index() {
    $products = Product::with('owner', 'memberInfo')->paginate($this->perPage);
    return View::make('layouts.sales', array('products' => $products, 'status' => 'all'));
}
1

There are 1 best solutions below

2
On BEST ANSWER

You can use Eloquent's reverse() function for collections.

public function index() {
    $products = Product::with('owner', 'memberInfo');
    $products = $products->reverse()->paginate($this->perPage);
    return View::make('layouts.sales', array('products' => $products, 'status' => 'all'));
}