Skip to main content
Sometimes you don’t want all properties included when transforming a data object. With lazy properties, you can include properties only when needed:
The songs key won’t be included when transforming:

Including Lazy Properties

Include the property explicitly:

Nested Includes

You can nest includes for properties within data objects:
Or combine includes:
Include all properties:

Types of Lazy Properties

Basic Lazy

Must be explicitly included:

Conditional Lazy

Only included when a condition is true:

Relational Lazy

Only included when a relation is loaded:

Default Included

Lazy property included by default:
Exclude it explicitly:

Auto Lazy

Reduce boilerplate with auto lazy properties:

Property Level Auto Lazy

Apply auto lazy to specific properties:

Auto Lazy with Model Relations

Automatically create lazy properties for model relations:
Specify the relation name if it differs:

Only and Except

Completely remove properties from the response:
Multiple keys:
only and except always take precedence over include and exclude.

Conditional Methods

Add includes/excludes based on conditions:
Using data object values:

Class-Level Includes

Define includes on the class:
Other methods:
  • excludeProperties() for excludes
  • exceptProperties() for except
  • onlyProperties() for only

Query String Includes

Allow includes via URL query strings:
Request:
Multiple properties:
Or using array input:

Allow All Includes

Return null to allow all properties:

Other Operations

  • allowedRequestExcludes() with exclude query parameter
  • allowedRequestExcept() with except query parameter
  • allowedRequestOnly() with only query parameter

Mutability

Includes/excludes only affect the data object once:
For permanent includes, use property methods or permanent methods:
Or with conditionals: