dongyan5239 2017-02-22 04:44
浏览 240
已采纳

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-22 04: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条)

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考