I have a piece of code like this:
$products = Product::all() if ($search_value) { $products = $products->where(\'name\', \'LIKE\', \"%$search_value%\
You're trying to use orderBy() method on Eloquent collection. Try to use sortByDesc() instead.
orderBy()
Alternatively, you could change $products = Product::all(); to $products = new Product();. Then all your code will work as you expect.
$products = Product::all();
$products = new Product();