dongyan5239 2017-02-22 04: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-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 MATLAB代码补全插值
  • ¥15 Typegoose 中如何使用 arrayFilters 筛选并更新深度嵌套的子文档数组信息
  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的