I'm getting results of products in category page. And i have system to hide sold out products.
Think that there exists ten pages for all products in category. When i check checkbox hide sold out products. The system returns ?page=10 But there is no product in ?page=10
I decided to use redict system.
$products = (new Product)->getProductsOfCategory($category->id);
$last_page = $products->lastPage();
if(request()->has('page'))
{
if(request()->get('page') > $last_page)
{
$location = categoryUrl($category->id, $category->category, NULL, NULL, $last_page);
//Output: http://dtl/en/cat/authentic-purses/120?page=7
return redirect()->to($location);
}
}
But i'm getting error
Method [links] does not exist on Redirect.
$products is paginated data.
UPDATE :
public function getProductsOfCategory($category_id){
$query = $this->where('category_id', $category_id);
$query = $this->productFilter($query);
$query = $this->productSorting($query);
return $query->paginate(18);
}
How can i get rid of this error ?
First of all getProductsOfCategory
should return instance of Illuminate\Pagination\Paginator
Then somewhere in your partial view you should use it method $products->links()
yo view pagination section on website.
This error is you get when you call this method on bad object for example: redirect()->links()
.
If this won't help You should paste here your partial view.
I solved the problem without using Laravel Redirect Method.
header("Location: ".$location);
die();
works fine instead of
return redirect()->to($location)