gpt4 book ai didi

php - Laravel 抛出 : method paginate does not exist error

转载 作者:行者123 更新时间:2023-12-02 06:51:42 26 4
gpt4 key购买 nike

我正在尝试在 laravel 中使用分页。所以我尝试检索所有交易并对其进行分页。我的流程是这样的,供您引用 view->controller->repository->model 。

我的仓库:

public function getall(){

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


return $this->transaction;

}

我的 Controller :

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

//dd($this->transaction);



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

}

在我的服务提供商下的 app.php 中,我确保我有分页:Illuminate\Pagination\PaginationServiceProvider::class,

但是没有别名。所以在我的 Controller 中我做了:使用 Illuminate\Pagination;

最佳答案

它不会按照你的方式工作。因为 all 方法会给你的 Collection。分页功能仅适用于 Eloquent\BuilderEloquent Model

如果需要对所有记录无条件分页,

\App\Transaction::paginate(10);

关于php - Laravel 抛出 : method paginate does not exist error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42382893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com