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

604media's avatar

Class paginator does not exist - Laravel 4.2

I tried to use Capsule to create my own mysql database connection. I got a error message from Laravel:

Class paginator does not exist

Then I added a line of code:

$capsule->getContainer()->bind('paginator', 'Illuminate\Pagination\Paginator');

Another error message was showed up:

Target [Illuminate\View\ViewFinderInterface] is not instantiable.

Here is the constructor:

use Illuminate\Database\Capsule\Manager as Capsule;

public function __construct($params){

$capsule = new Capsule;
$params = array_merge(static::$baseParams, $params);
$capsule->addConnection($params);
//$capsule->getContainer()->bind('paginator', 'Illuminate\Pagination\Paginator');
$this->db = $capsule->getConnection();
}

ps:

$this->db->table('table_name')->get() work!
$this->db->table('table_name')->paginate(4) doesn't work! 

How to fix this? Thanks !

0 likes
3 replies
tios's avatar

Pagination uses Laravel routing. So you can't use it outside of a Laravel app.

Inside a Laravel app every model can have its own connection.

class MyModel extends Model {
    protected $table = 'my_table';
    protected $connection = 'mysql2';
    protected $primaryKey = 'my_id';

vikkio88's avatar

probably is too late, but I solved it using take and offset, coding a scope:

    public static function scopePage($query, $pagination)
    {
        $limit = $pagination['limit'];
        $offset = ($pagination['page'] - 1) * $pagination['limit'];
        return $query->take($limit)->skip($offset);
    }

Please or to participate in this conversation.