Thursday, March 9, 2017

Change laravel pagination response object

When I use laravel pagination, I get an object like this:

{
    "per_page": 1000,
    "current_page": 2,
    "next_page_url": null,
    "prev_page_url": null,
    "from": null,
    "to": null,
    "data": []
}

I would like to add to that object a 'filters' attribute in my controller in order to return in the response what filters has been added. Like this:

{
    "per_page": 1000,
    "current_page": 2,
    "next_page_url": null,
    "prev_page_url": null,
    "from": null,
    "to": null,
    "data": [],
    "filters" : []
}

When I try to do so in my controller, like

$paginated->filters = [ ];

It makes no effect, the response object remains the same.

Any ideas ? Thanks in advanced.



via Gonzalo Filón

Advertisement