2016-05-01 58 views
0

我收到了类别页面中产品的结果。我有系统来隐藏已售完的产品。Laravel 5.2重定向到页面查询字符串

认为有10个页面适用于所有类别的产品。当我检查复选框隐藏售完产品。系统返回?page = 10但是目前没有产品?page = 10

我决定使用redict系统。

$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); 
    } 
} 

,但我发现错误

Method [links] does not exist on Redirect.

$产品进行分页数据。


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); 
} 

我怎样才能摆脱这种错误的?

+0

我们在这里失踪的代码。你可以转储'$ location'的输出吗?另外 - 我建议寻找为什么系统返回一个没有产品的页面,而不是修复如果用户去那里会发生什么。 – CmdrSharp

+0

我更新了位置输出 –

+0

系统正在返回没有产品的页面。因为我发布到同一页面。只显示股票。 –

回答

0

所有getProductsOfCategory首先应该返回的Illuminate\Pagination\Paginator 实例,然后在某处你的部分观点,你应该使用它的方法$products->links()在网站上哟视图分页部分。

当您在不良对象上调用此方法时出现此错误,例如:redirect()->links()

如果这不起作用你应该在这里粘贴你的部分视图。

+0

当我dd产品 - >链接()我得到的结果。该方法是Paginator的一个实例 –

+0

好了,然后显示“getProductsOfCategory”方法的主体。 –

0

我解决了问题,而不使用Laravel重定向方法。

header("Location: ".$location); 
die(); 

正常工作,而不是

return redirect()->to($location) 
+0

很高兴你解决了它!作为旁注,你可以'exit(header(“Location:”。$ location));'。此外,将您自己的答案标记为已解决! :) – CmdrSharp