{"enrichment":{"faq":[{"a":"laravel-api-resource-patterns teaches you to structure API Resources for clean, consistent JSON responses. Best practices include using whenLoaded() to prevent N+1 queries, defining conditional attributes for flexible responses, properly loading relationships before transformation, and organizing collections with pagination metadata. Resources act as a transformation layer between your models and API output.","q":"What are laravel api resource best practices?"},{"a":"laravel-api-resource-patterns covers using whenLoaded() to safely include relationship data only when it's already loaded on the model. This prevents the resource from triggering additional queries. Load relationships eagerly in your controller (e.g., User::with('posts')->get()), then in your Resource class use $this->whenLoaded('posts') to conditionally include them without extra database hits.","q":"How do you prevent N+1 queries using whenLoaded in resources?"},{"a":"laravel-api-resource-patterns explains conditional attribute inclusion through methods like when() and whenLoaded(). Define fields that appear only under certain conditions\u2014for example, showing admin-only fields only to authenticated admins, or including timestamps only when requested. This keeps your API responses flexible and secure without duplicating resource classes.","q":"How can laravel resources transform models to JSON with conditional attributes?"},{"a":"laravel-api-resource-patterns demonstrates wrapping paginated results in ResourceCollections, which preserve pagination metadata (current_page, total, etc.) alongside your transformed data. Load relationships before passing to the collection, use whenLoaded() for optional includes, and leverage the collection's meta() method to attach custom metadata like links or filtering info.","q":"How do you handle pagination and relationships in laravel resource collections?"},{"a":"laravel-api-resource-patterns covers resource wrapping\u2014automatically nesting your data under a key (e.g., 'data')\u2014and unwrapping to return raw arrays. Wrapping provides consistent envelope structure for collections and error responses; unwrapping simplifies single-resource endpoints. Control this via config or the resource's wrap() method to match your API design.","q":"What is the purpose of laravel resource wrapping and unwrapping?"},{"a":"laravel-api-resource-patterns shows adding HATEOAS links and metadata to resources via the with() method and custom toArray() logic. Include self links, related resource links, and pagination links in collections. Attach metadata like total counts, filtering info, or API version. This makes your API self-documenting and easier for clients to navigate.","q":"How do you structure RESTful API responses with links and metadata?"}],"shadow_tags":["json-transformation","eager-loading","pagination-metadata","hateoas-links","response-formatting","query-optimization","conditional-fields","rest-api-design","relationship-handling","data-serialization"],"summary_rewrite":"Learn how to structure Laravel API Resources for clean model transformation and consistent JSON responses. This skill covers conditional attributes, relationship loading, collections with pagination, and techniques to prevent N+1 queries."},"files":[{"bytes":6349,"path":"skills/laravel-api-resource-patterns/SKILL.md","sha256":"1d9e03fa21060edea404e6e4be72c5012b98fa2c8b8f0b05b9007aec97ffa57d","url":"https://skillfed.io/files/iSerter/laravel-claude-agents/laravel-api-resource-patterns/40a60aa9/SKILL.md"}],"id":"iSerter/laravel-claude-agents/laravel-api-resource-patterns","links":{"html":"https://skillfed.io/iSerter/laravel-claude-agents/laravel-api-resource-patterns","md":"https://skillfed.io/iSerter/laravel-claude-agents/laravel-api-resource-patterns.md","repo":"https://github.com/iSerter/laravel-claude-agents"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":8,"language":"PHP","last_updated":"2026-04-19","license":"MIT","name":"laravel-api-resource-patterns","publisher":"iSerter","stars":41},"relations":{"similar":[{"id":"rawveg/skillsforge-marketplace/laravel"},{"id":"personamanagmentlayer/pcl/php-expert"},{"id":"Jeffallan/claude-skills/laravel-specialist"},{"id":"noartem/skills/laravel-api-resources-and-pagination"},{"id":"JustSteveKing/laravel-api-skill/laravel-api"},{"id":"noartem/skills/laravel-api"},{"id":"iSerter/laravel-claude-agents/laravel-authorization-patterns"},{"id":"iSerter/laravel-claude-agents/laravel-validation-patterns"},{"id":"iSerter/laravel-claude-agents/laravel-notification-patterns"},{"id":"AsyrafHussin/agent-skills/laravel-best-practices"}]},"slug":{"owner":"iSerter","repo":"laravel-claude-agents","skill":"laravel-api-resource-patterns"},"version":"40a60aa9"}
