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条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统