laravel 4 paginate collection

后端 未结 3 1611
天涯浪人
天涯浪人 2021-01-06 14:30

I cant create a proper pagination system using laravel 4. I have the following models and function that return collections:

Model Restaurant:

public          


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-06 14:35

    I created a subclass of Collection and implemented my own paginate method

    public function paginate($perPage) {
        $pagination = App::make('paginator');
        $count = $this->count();
        $page = $pagination->getCurrentPage($count);
        $items = $this->slice(($page - 1) * $perPage, $perPage)->all();
        $pagination = $pagination->make($items, $count, $perPage);
        return $pagination;
    }
    

提交回复
热议问题