Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel抛出:方法paginate不存在错误_Php_Laravel_Pagination_Laravel Eloquent - Fatal编程技术网

Php Laravel抛出:方法paginate不存在错误

Php Laravel抛出:方法paginate不存在错误,php,laravel,pagination,laravel-eloquent,Php,Laravel,Pagination,Laravel Eloquent,我正在尝试在laravel中使用分页。因此,我尝试检索所有事务并对其进行分页。对于您的参考视图->控制器->存储库->模型,我的流程如下所示 myrepository: public function getall(){ $this->transaction = Transaction::all(); return $this->transaction; } mycontroller: public function getall(){ $tra

我正在尝试在laravel中使用分页。因此,我尝试检索所有事务并对其进行分页。对于您的参考视图->控制器->存储库->模型,我的流程如下所示

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]);

}
在我的app.php中的服务提供者下,我确保有分页:illumb\pagination\PaginationServiceProvider::class

但是没有别名。
所以在我的控制器中,我做到了:使用照明\分页

这不符合你的方式。因为
all
方法将给出您的
集合
。Paginate函数仅适用于
Eloquent\Builder
Eloquent模型

如果需要无条件地对所有记录进行分页

\App\Transaction::paginate(10);
你喜欢这样吗

//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);

}   
 $transactions = Transaction::all();

 $transactions = Transaction::orderBy('name')->paginate(10);

 return view('index', compact('transactions'));

将以下功能添加到存储库中

存储库 控制器
如果要使用
orderBy()
paginate()

用过这样的东西

//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);

}   
 $transactions = Transaction::all();

 $transactions = Transaction::orderBy('name')->paginate(10);

 return view('index', compact('transactions'));

\App\User::->paginate(10);应该是\App\User::paginate(10);我用这个方法。。。我看到前10个成功。。。但我看不到底部的页面??它只显示前10页,因为你正在拉10页。你可以将值增加到20或任何你想要的值。是的,我知道。。。但是我看不到我的视图中的页码为什么?您在视图中使用了“{{$transactions->links()}}”吗?您使用的是什么版本的Laravel?从控制器中删除
Use Illimunte\Pagination
。它已经包含在雄辩中。如果是,请接受它,以便对其他人有所帮助;)默认情况下,Laravel支持Paginate函数,无需创建新函数。检查@geckob答案。