laravel 调用未定义的方法 Illuminate\Database\Query\Builder::links()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25247600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:56:03  来源:igfitidea点击:

Call to undefined method Illuminate\Database\Query\Builder::links()

phpmysqllaravelpaginationpaginator

提问by allan

whats up ? I have a little problem with Laravel Paginator.

这是怎么回事 ?我对 Laravel 分页器有一个小问题。

I built the function using order by and paginator, but I'm getting the error message "Call to undefined method Illuminate \ Database \ Query \ Builder :: links () (View: C: \ wamp \ www \ laravel \ app \ views \ frontend \ premios.blade.php). "

我使用 order by 和 paginator 构建了该函数,但收到错误消息“调用未定义的方法 Illuminate\Database\Query\Builder::links()(视图:C:\wamp\www\laravel\app\views \前端\premios.blade.php)。”

============= My Function ==============

============我的功能==============

public function premios()
{
$this->layout->content = View::make('frontend.premios')->with('premiostexto',PremiosTexto::all()) ->with('premios', Premios::orderBy('ordem', 'ASC')->paginate(5));
}

==========My View============

==========我的观点============

@foreach($premios as $premios)
    <span class="tituloPremio">{{$premios->titulo}}</span>
    <span class="dataPremio">{{$premios->data}}</span>
@endforeach

    {{ $premios->links() }}

I tried putting "$premios->links()" inside and outside the foreach.Without pagination everything works good

我尝试在 foreach 内外放置“$premios->links()”。没有分页,一切正常

回答by Joseph Silber

You are overriding the $premiosvariable in the foreach. Use it as singular form in the foreach:

您正在覆盖$premios的变量foreach。在 中将其用作单数形式foreach

@foreach($premios as $premio)
    <span class="tituloPremio">{{$premio->titulo}}</span>
    <span class="dataPremio">{{$premio->data}}</span>
@endforeach

{{ $premios->links() }}