dongyan5239 2017-02-21 20:44
浏览 241
已采纳

Laravel抛出:方法paginate不存在错误

I am trying to use pagination in laravel. so i try to retrieve all the transactions and paginate it. my flow goes like this for your reference view->controller->repository->model .

myrepository:

public function getall(){

    $this->transaction = Transaction::all();


    return $this->transaction;

}

mycontroller:

 public function getall(){   
  $transactions = $this->transaction->getall()->paginate(10);

    //dd($this->transaction);



    return view('transactions', ['transactions' => $transactions]);

}

in my app.php under service providers i made sure i have pagination: Illuminate\Pagination\PaginationServiceProvider::class,

but there is no aliases though. so in my controller i did : use Illuminate\Pagination;

  • 写回答

4条回答 默认 最新

  • dsfdfdfd6576578 2017-02-21 20:55
    关注

    Do like this

    //in repository
    public function getAll($limit)
    {
        $this->transaction = Transaction::paginate($limit); //Use paginate here.
         return $this->transaction;
    }
    
    //in controller 
    public function getall() {
        $transactions = $this->transaction->getall(10);
    
    }   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部