在非对象上调用成员函数connection()

时间:2016-05-19 14:47:02

标签: model eloquent slim paginate

我正在开发一个带有slim 3的API。我正在尝试使用fractals paginate()但是由于模型的原因我不断收到错误。我一直在研究谷歌,仍然没有找到适合我的问题的答案。

这是模特:

class wholesalers extends Model {

    protected $table = 'tbl_wholesalers';

}

我的控制员:

try {
    $fractal = new Manager();
    $fractal->setSerializer(new DataArraySerializer());
    #$wholesalers = $this->db->table('tbl_wholesalers')->select('*')->get();
    $paginator = wholesalers::paginate();
    $wholesalers = $paginator->getCollection();

    if ($wholesalers) {
        $resource = new Collection($wholesalers, new wholesalersTrans);
        $resource->setPaginator(new \League\Fractal\Pagination\IlluminatePaginatorAdapter($paginator));
        $data = $fractal->createData($resource)
            ->toArray();

        $final = $response->withStatus(200)
                ->withHeader("Content-Type", "application/json")
                ->write(json_encode($data['data'], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));

        $this->logger->info('Wholesalers viewed with success.');

        return $final;
    } else {
        $this->logger->error('No wholesalers found!');
        return $response->withStatus(404)
                        ->write('No wholesalers found!');
    }
} catch (Exception $e) {
    $this->logger->error($e->getMessage());
}

错误:

Fatal error: Call to a member function connection() on a non-object in ***/vendor/illuminate/database/Eloquent/Model.php on line 3280

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

看起来你没有连接到Eloquent。您应该在代码中的某处构建Eloquent。