dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

undefined method getDefaultIncludes() #952

Closed banandam closed 8 years ago

banandam commented 8 years ago

Country hasmany Cities cities belongsto Country Country hasMany States States belongsto Country

Relation ship set. after i accesses paginate CountryTransformer get on undefined method issue. Errors given below

Call to undefined method app\Transformers\CountryTransformer::getDefaultIncludes() in \lumen\vendor\dingo\api\src\Transformer\Adapter\Fractal.php on line 193

Code:

    $countries = Country::filterByRequest($request)->paginate(20);
return $this->response->paginator($countries, new CountryTransformer);
jasonlewis commented 8 years ago

Are you extending Fractals TransformerAbstract class?

banandam commented 8 years ago

Yes i am not extend. Thx. it's my mistake. and one more question

Cities paginate include the state and country Transformer. out put given below.

But state reference also add "data" attribute. How can skip it ?

{ "data": [ { "id": 1, "name": "karla", "state_id": 1, "country_id": 1, "State": { "data": { "id": 1, "name": "Tamil Nadu", "country_id": 1 } }, "Country": { "data": { "id": 1, "name": "PAKI", "iso2": "IN", "iso3": "IND" } } } ], "meta": { "pagination": { "total": 1, "count": 1, "per_page": 20, "current_page": 1, "total_pages": 1, "links": [] } } }

hemant-brb commented 7 years ago

if you will remove that data attribute then how will you format the response result that includes meta data ? it is required to identify the data array without it how will you merge the array's ?