使用下面的代码,我想要的是对我创建的查询进行分页。但是,当我尝试在 get 之后添加分页时,它会引发错误。我想保持 get 因为我想限制在 $fields 上设置的列。对这件事进行分页应该是什么更好的主意?或者什么是获取和限制列的好替代品?
我尝试了什么:
->get($this->fields)->paginate($this->limit)
我的控制器的一部分:
class PhonesController extends BaseController {
protected $limit = 5;
protected $fields = array('Phones.*','manufacturers.name as manufacturer');
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
if (Request::query("str")) {
$phones = Phone::where("model", 'LIKE', '%'. Request::query('str') . '%')
->join('manufacturers', 'manufacturers_id', '=', 'manufacturers.id')
->get($this->fields);
} else {
$phones = Phone::join('manufacturers', 'manufacturers_id', '=', 'manufacturers.id')
->get($this->fields);
}
return View::make('phones.index')->with('phones', $phones);
}
}