Hello Guys,
I'm wondering for a wierd issue while using laravel pagination.
i wrote this code block:
Route::get('products/{categoryId?}', function($categoryId = null) {
if($categoryId) {
$products = \App\Product::where('active', 'y')
->where('category_id', $categoryId)
->paginate(12);
} else {
$products = \App\Product::where('active', '=', 'y')->paginate(12);
}
return view('frontend.pages.products', ['products' => $products]);
});
And its working, but this one:
Route::get('products/{categoryId?}', function($categoryId = null) {
$products = \App\Product::where('active', 'y');
($categoryId) AND $products->where('category_id', $categoryId);
$products->paginate(12);
return view('frontend.pages.products', ['products' => $products]);
});
Not working and i get:
Call to undefined method Illuminate\Database\Query\Builder::render()
Error.
Here is my view:
{!! $products->render() !!}