vendredi 18 mars 2016

Laravel 5 + DingoApi paginate

i'm developing an api with Laravel and DingoAPI which returns the message threads of the user with pagination.

$threads = Thread::forUser($currentUserId)->latest('updated_at')->simplePaginate(1);
return API::response()->array($threads);

and i get this kind of response :

{
  "per_page": 1,
  "current_page": 1,
  "next_page_url": "http://ift.tt/1Rr83Nt",
  "prev_page_url": null,
  "from": 1,
  "to": 1,
  "data": [
    {
      "id": 1,
      "subject": null,
      "created_at": "2016-03-18 12:33:38",
      "updated_at": "2016-03-18 12:33:38",
      "deleted_at": null
    }
  ]
}

What can i do to remove some field of the response ? i just need data and next_page_url …

i tried this way :

$array_response = [
        'next_page_url' => $threads['next_page_url'],
        'data' => $threads['data']
        ];

but only null values are returned. I guess Dingo Api is doing some work behind the scene…



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire