AES Encryption Explained: How It Works and Why It Matters
Jun 23, 2026
Generate Laravel JsonResource and ResourceCollection classes with field mappings, conditional relations, and metadata.
Singular CamelCase, e.g. Post, User, Product
Auto-filled as {Model}Resource.
Leave empty for no wrapping.
Map each API response key to an expression. Supports $this->attribute, $this->relation->field, and helpers.
Relations that should only appear when they have been eager-loaded (whenLoaded).
Optional JSON object for the with() method. Used in collection for pagination links/meta.
This tool helps you create Laravel API Resource and Resource Collection classes. Follow these steps:
Post. The resource class name auto-fills.$this->attribute or expression.whenLoaded to include relations only when eager-loaded.with() metadata and pagination links for collections.{Model}Resource.php.API Resources are classes that transform your Eloquent models and collections into JSON responses. They live in app/Http/Resources/ and provide a clean way to shape API output, hide attributes, include relationships, and add metadata.
Resource (extends JsonResource) transforms a single model instance. ResourceCollection (extends ResourceCollection) transforms a collection of models, often with pagination links.
whenLoaded('relation') includes the field only if the relation has been eager-loaded. This prevents N+1 queries while still allowing the resource to include relation data when available.
Laravel 11 no longer wraps resources by default. If your API client expects a data wrapper (common in JSON:API), set the Wrap Key to data. Leave it empty for no wrapping.
Blog
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026
Jun 23, 2026