2017-05-29 49 views
1

我试图将范围链接到分页方法,但是我改为使用方法的badmethodcallexception;将范围链接到分页方法

$products = Product::paginate(3)->forstore(); 

forstore方法是范围。

public function scopeForstore($query) { 
    ... 
} 

我该如何实现所需的结果,即添加范围到分页查询?

回答

2

->paginate(x)->get()->first() ...方法来结束查询。他们告诉查询是时候返回结果(并返回集合或模型)。你正在做的是在集合上调用范围而不是查询。

交换他们身边:

$products = Product::forstore()->paginate(3); 
2

你应该调用PAGINATE功能之前,你的应用范围,直接在制造商,像这样:

Product::forstore()->paginate(3);