Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dyasis's avatar

Method render does not exist...

I'm trying to do a simple pagination but I am getting the following error:

ErrorException in Macroable.php line 81: Method render does not exist.

In my controller I have:

$providers = \App\Providers::paginate(5);
        return view('dashboard.index', compact('providers'));

in my view I am calling

{!! $providers->render() !!}

what am I missing here? thanks

0 likes
29 replies
bobbybouwmann's avatar

Works fine for me... Are you sure App\Providers is a model?

When I run this

dd(\App\User::paginate(5));

I get this as response

LengthAwarePaginator {#126 ▼
  #total: 11
  #lastPage: 3
  #items: Collection {#131 ▶}
  #perPage: 5
  #currentPage: 1
  #path: "http://random.app"
  #query: []
  #fragment: null
  #pageName: "page"
}
RoboRobok's avatar

It works for me as well. Which version of Laravel are you using?

Dyasis's avatar

Yes sir, if I remove the paginate(5) I get my rows from the db, I just wanted to add pagination lol but then I get that error, I'm at a loss...

Dyasis's avatar
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Providers extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'status',
        'name',
        'access_hours',
        'access_info'
    ];

    /**
     * Get the user(s) associated with the provider.
     *
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function users()
    {
        return $this->belongsToMany('App\User');
    }

}
bobbybouwmann's avatar

And you say that the following works fine?

dd(\App\Providers::all());
Dyasis's avatar

Yes, if I use dd I get

Collection {#191 ▼
  #items: array:5 [▼
    3 => Providers {#203 ▶}
    4 => Providers {#204 ▶}
    2 => Providers {#202 ▶}
    0 => Providers {#200 ▶}
    1 => Providers {#201 ▶}
  ]
}
Dyasis's avatar

If I remove the

{!! $providers->render() !!}

from my view and leave paginate(3) in my controller, it works, it will only give me 3 results, if I change it to 4, it will give me 4, it's just the stupid render() method thats for what ever reason not being found...

bobbybouwmann's avatar

That is odd... This should work fine.. Have you tried to run composer dump-autoload -o or removing your vendor directory and running composer install again? Might be something that is not loaded correctly. I have no clue what else it could be...

Dyasis's avatar

well, I did both of those, including deleting my vendor directory, and still same thing.. this is crazy

Dyasis's avatar

well, this keeps getting better, I created a new install of a laravel project and still get the same error...

RoboRobok's avatar

Is that a large project? Your code is perfectly fine, so it must be either some service provider or view composer screwing it up, or some lower level issue.

Dyasis's avatar

Not that large at all, that's what I don't understand lol, I guess ill start from scratch..

RoboRobok's avatar

Can you start a new project and just add as little as possible? That would be just the model, route, controller and view. See what happens. :)

tucq88's avatar

This is my solution, I have to create the pagination manually. I'm using laravel 5.1

    $page = Paginator::resolveCurrentPage('page');
    $perPage = 10;
    $news = News::query();
    $news = $news->skip(($page - 1) * $perPage)->take($perPage + 1)->get();

        $paginator = new Paginator(
                $news,
                $perPage,
                $page,
                [
                    'path' => Paginator::resolveCurrentPath(),
                    'query' => $request->all()
                ]
            );

            $news = $paginator->items();

I'm not sure but default Eloquent return Eloquent list, that's why it doesn't have render method, There are ony 2 objects that have that methods are Illuminate\Pagination\Paginator and Illuminate\Pagination\LengthAwarePaginator.

gustre's avatar

If you have created your own custom service provider, did you consider registering it in the config/app.php along with the other application service providers?

BrianDillingham's avatar

Just came across the same issue, only after I chunk() solved by moving the render()above chunk() could be because the collection was altered

mstrauss's avatar

I had the same issue, using 5.1, and as the last post suggested the error had to do with modifying the collection. In my case I originally used a sortBy after calling paginate. Once I removed the sortBy it worked as expected.

greenhatman's avatar

I had a similar problem. This issue was that paginate() didn't actually change my collection into a paginator object, but it returns a paginator object.

$tutors = \App\User::tutors()
            ->with('tutorProfile')
            ->with('nationality');
        if ( ! empty($_REQUEST['global-search-wildcard'])) {
            $tutors = $tutors
                ->where('name', 'like', "%{$_REQUEST['global-search-wildcard']}%")
                ->orWhere('surname', 'like', "%{$_REQUEST['global-search-wildcard']}%")
                ->orWhere('phone', 'like', "%{$_REQUEST['global-search-wildcard']}%")
        }
        $tutors->orderBy('name')->orderBy('surname');
        $tutors->paginate(15);

I just had to change

$tutors->paginate(15);

to

$tutors = $tutors->paginate(15);
ChrisArter's avatar

Has anyone solved this yet? I'm on 5.3 and encountering the exact same thing as OP.

ChrisArter's avatar

Actually, I just made a bit of progress with figuring this out.

I got the exact same errors, but it was because I was passing the collection to a partial view to display the results via an @include. the I tried to pass the collection to @include but it still didn't work.

I pulled all of the markup out of the partial and put it in the main view and suddenly the pagination links worked beautifully. But it was not working when nested in an include, despite me trying to push it there with the second argument of @include.

Sorry, typing this on zero sleep, haha. Hopefully that helps someone else.

Please or to participate in this conversation.