简体   繁体   中英

Paginate Issue Laravel 5.6

Was wondering if someone could check this out and let me know what I'm doing wrong. I'm trying to use paginate on a database query and render it in my view.

Is my DB query incorrect? I was following the docs to create it. Also read that I needed to remove ->get() when using paginate.

This is what is giving the error on my view: {{$item->paginate(4)}} , same happens if I use {{$item->links(4)}}

Everything renders fine if I remove paginate from the query in the controller..?

Here is what I'm working with.

Controller:

        public function index()
{
   // $news = DB::table('news')->orderBy('id', 'DESC')->paginate(4);
    $news = DB::table('news')->select('id','title','description','listing_image','created_at','updated_at')->orderBy('id', 'DESC')->paginate(4);
    return view('news.index',compact('news'));
}

View: ( Getting error: Call to undefined method stdClass::paginate() )

@if ($news->count())
@foreach($news as $item)
...html
 @if ($item->listing_image)
...more html

    @else
    @endif 

... more html

@endforeach

{{$item->paginate(4)}}

@endif 

将{{$ item-> paginate(4)}}更改为{{$ news-> links()}}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM