I have a piece of code like this:
$products = Product::all()
if ($search_value) {
$products = $products->where(\'name\', \'LIKE\', \"%$search_value%\
You are first getting all()
data and then trying to sort which is wrong. You have to fix this by removing
$products = Product::all()
and changing your code into something like this
if ($search_value) {
$products = Product::where('name', 'LIKE', "%$search_value%");
}
else {
$products = Product::orderBy('created_at', 'desc')->skip(10)->take(10)->with('tags')->get();
}
Hope you get idea to tweak your code.