Pilot logbook
Bucket list

Include Laravel model relations on demand

1 minutes read -

This open source package can be a huge performance boost for your restful Laravel/Lumen api because it allows frontend developers to request on demand any entity relation by simply adding the relation name to the request.

Let's say there's a page that shows a list of users with their order history, simple! Another page that uses the same endpoint will need users without their order history, well, not possible because your endpoint always gives you the order history whether you need it or not!

Typically a user could have various different relations like (Preferences, addresses, credit cards, etc..) it becomes expensive to call such endpoint that loads all those relations in memory and response...

This is where Laravel relation parser package comes in handy, you can simple request which relation you need from the frontend.

Here's an example for an API call to users endpoint requesting the user orders to be additionally loaded


Here's another example requesting the user orders AND addresses.


Related posts