Mik*_*chy 2 php pagination laravel laravel-eloquent
我试图在laravel中使用分页.所以我尝试检索所有的交易并对其进行分页.我的流程就像你的参考视图 - > controller-> repository-> model.
myrepository:
public function getall(){
$this->transaction = Transaction::all();
return $this->transaction;
}
Run Code Online (Sandbox Code Playgroud)
myController的:
public function getall(){
$transactions = $this->transaction->getall()->paginate(10);
//dd($this->transaction);
return view('transactions', ['transactions' => $transactions]);
}
Run Code Online (Sandbox Code Playgroud)
在我的app.php服务提供商下我确定我有分页:Illuminate\Pagination\PaginationServiceProvider :: class,
但是没有别名.所以在我的控制器中我做了:使用Illuminate\Pagination;
它不适合你的方式.因为all方法会给你的Collection.Paginate功能仅适用于Eloquent\Builder或Eloquent Model
如果您需要在没有条件的情况下对所有记录进行分页,
\App\Transaction::paginate(10);
Run Code Online (Sandbox Code Playgroud)