通过传参的形式,来进行是否分页?
无意写了一句代码,不知道什么意思,求解答?
protected $model;
public function __construct(Category $category)
{
$this->model = $category;
}
public function getLists($request, $isPage = 'get', $order = 'created_at', $sort = 'desc')
{
return $this->model->orderBy($order, $sort)
->$isPage();
}
如代码所示,我在 getLists
中有一个参数 $isPage
。本意是传入 get
,就是获取全部数据,paginate
就是分页。结果就有了上述代码,$this->model->orderBy($order, $sort)->$isPage();
, 并且可以成功在分页与不分页之间切换,请问为什么可以这样?麻烦解答!
推荐文章: