mercredi 18 janvier 2017

Laravel : Dingo/API Pagination custom root key

I've developed an API with Laravel 5 and Dingo/API.

Following the documentation, i used pagination and my code look like that

$users = User::paginate(50);

return $this->response->paginator($users, new UserTransformer);

Unfortunately, the response root key is "data"

{
"data": [
{
  "id": 1,
  "username": "superuser", 
......

I'd like to change the "data" key to a custom one, because in my case, emberjs get this response and try to make a link with a "datum" model which doesn't exist, the key need to be set with the same name as the ember model in case of a RESTAdapter.

I already tried some parameters in the response but nothing change

return $this->response->paginator($users, new UserTransformer, ['key' => 'users']);

or

return $this->response->paginator($users, new UserTransformer, ['identifier' => 'users']);

Nothing work, i'm stuck with the "data" key.

Is someone have a solution ?

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire