api-resource-patterns

Standardize Laravel API Resource patterns for consistent model-to-payload transformations.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/JefersonCCJM/hotel_san_pedro --skill api-resource-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: api-resource-patterns
Source: https://github.com/JefersonCCJM/hotel_san_pedro/tree/main/.agents/skills/api-resource-patterns
Command: npx skills add https://github.com/JefersonCCJM/hotel_san_pedro --skill api-resource-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Standardize Laravel API Resource patterns to ensure consistent transformation of models into API payloads.

Core Features & Use Cases

  • Canonical Resource and ResourceCollection structures with toArray and toArray variations
  • Efficient and safe relationship loading with whenLoaded and mergeWhen
  • Clear guidelines for conditional attributes, wrapping, and hypermedia links

Quick Start

Use a standard PostResource and PostCollection pattern to format API responses in your Laravel app.

Frequently Asked Questions about api-resource-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I standardize Laravel API Resources for consistent model transformations?

Use conditional attributes in Laravel API Resources with the whenLoaded and mergeWhen methods. These allow efficient and safe relationship loading, ensuring nested relationships are only included in the API payload when they have actually been loaded from the database.

What is the best way to handle nested relationships in Laravel API Resources?

Yes, you can format Laravel collection responses by implementing standard PostCollection patterns. This provides a canonical ResourceCollection structure that standardizes how multiple models are transformed and wrapped within your API response payloads.

When do I need resource wrapping and conditional attributes in Laravel API responses?

Laravel API Resource transformations apply to any Laravel application needing reliable API payload formatting. They are suited for projects requiring consistent resource structures, conditional attribute handling, and safe nested relationship loading across single resources and collections.

Why does my Laravel API Resource include unloaded relationship data in the response?

Your Laravel API Resource might include unloaded relationship data if you are not using the whenLoaded conditional method. Applying whenLoaded ensures that nested relationship data is only appended to the API payload when the relationship is explicitly loaded.