Skip to main content
The transform method defines what data your resource returns. Every time Exo sends an API response or delivers a webhook, it calls transform to build the payload.

Basic transform

Return an array of the fields you want to expose:
This is the array that API consumers and webhook subscribers receive.

Choosing which fields to include

You control exactly what gets exposed. A common pattern is to exclude sensitive or internal fields:
Only include fields that external tools and automations need. Leave out internal data like cost margins, admin notes, or soft-delete timestamps.
You can include data from related models:
When including relationships, make sure to eager-load them in baseQuery() to avoid performance issues. See the search & queries page.

Date formatting

Exo automatically formats date fields as ISO-8601 strings (e.g. 2026-03-28T14:30:00+00:00). This applies to any attribute listed in the model’s $dates array or cast as a date. You don’t need to format dates yourself — if you include a date field in your transform output and the model recognizes it as a date, Exo handles the formatting through the resolve method.

Using toArray for quick setup

For a quick start, you can return the entire model:
This works but exposes all visible attributes. It’s better to explicitly list fields so you control what external tools see — especially if you add new columns to the model later.
Be careful with toArray(). New columns added later can be exposed automatically, including fields you did not intend to publish to external systems.