Published 7 months ago by jlanzas
Is there anyway I can pass variable to a resource collection? I have been looking around but can't figure it out.
Any help will be greatly appreciated.
Thank you for the answers guys... @skliche I'm working with datatables and pagination. So I need to send back, the page number, total pages, item count, per-page amount, sort field and sort order.
I can get a few fields like the item count, total pages, but the page number is send on a variable the same goes for the per-page amount and the sorting field and order.
So thats the reason I want to send those fields to the ResourceCollection.
You can add both meta data and pagination information. Did you look at https://laravel.com/docs/master/eloquent-resources#adding-meta-data and https://laravel.com/docs/master/eloquent-resources#pagination?
You can overwrite the default constructor (
public function __construct($resource)) if you need to pass additional data at that point.