0
votes

I am working a project and I would want to use a where clause, paginate and then sort in the collection in specific order. I have tried the result below but keeps throwing the errors below Method:

Illuminate\Database\Eloquent\Collection::links does not exist. (View: /Applications/XAMPP/xamppfiles/htdocs/vermex/resources/views/equipments.blade.php)

The Product model is where I am getting the data and store in a variable called $equipment. If there is a better way of doing this, please help.

public function equipments()
    {
        $equipments = Product::where('product_category_id', 3)->paginate(2)- 
       >sortByDesc('id');

        return view('equipments', compact('equipments'));
    }
1
please add you view code, it will give us more information. The error could be in blade... :-)redcenter

1 Answers

1
votes

Try putting the orderBy before the paginate

$equipments = Product::where('product_category_id', 3)->orderBy('id', 'desc')->paginate(2);

sortByDesc is a collection method.

paginate will need to be last for links to be available in the blade view.