abhishek009's avatar

Pagination in L5

I have this code :

$status = statuses::whereIn('uid', $following)->with('user')->latest()->paginate(5);

In blade :

{{ $status->render() }}

Showing this error :

Call to undefined method Illuminate\Database\Query\Builder::render() (View: C:\xampp3\htdocs\resources\views\home.blade.php)
0 likes
11 replies
taijuten's avatar

What is the render function you're trying to call? It's saying that it's not set.

jackpopp's avatar

Probably worth showing more of your controller and view code, what do you get if you just dd the status variable?

abhishek009's avatar

@jackpopp

public function index()
{
   $status = statuses::whereIn('uid', $following)->with('user')->latest()->paginate(5);
    return view('home',compact('status'));
}

In view :

 {{ $status->render() }}
taijuten's avatar

You haven't specified, what is render()?

Is this a function you've declared somewhere else? Is it a property you're trying to call?

taijuten's avatar

You need to pass through the Paginator Class to your view. This pagination instance will be either

Illuminate\Pagination\Paginator

or

Illuminate\Pagination\LengthAwarePaginator

depending on what you need.

bestmomo's avatar

Your code should work as this, could you show what you get with dd($status) ? You should get a LengthAwarePaginator object.

pmall's avatar

@taijuten He is using the paginator method so there is a render method on the returned object.

abhishek009's avatar
abhishek009
OP
Best Answer
Level 3

Ah !!! I got the problem, Problem was in foreach loop. I passed status in view

return view('home',compact('status'));

And then I used foreach loop:

@foreach($status as $status)

I had no problem of accessing elements using $status variable however when I user

{{ $status->render() }}

It doesn't work So, I just needed to change foreach to :

@foreach($status as $statuses)

Anyway Thanks guys for quick help :-)

Please or to participate in this conversation.