laravel-api-resources-and-pagination

Shape Laravel models into versioned, paginated API responses with conditional fields.

Updated Jun 8, 2025
One-click install
npx skills add https://github.com/noartem/kawa --skill laravel-api-resources-and-pagination-noartem
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-api-resources-and-pagination
Source: https://github.com/noartem/kawa/tree/main/ui/.ai/skills/laravel-api-resources-and-pagination
Command: npx skills add https://github.com/noartem/kawa --skill laravel-api-resources-and-pagination-noartem

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Represent models via Laravel API Resources to keep transport concerns out of Eloquent, ensuring stable payloads and easier client consumption.

Core Features & Use Cases

  • Use Resources to transform models into consistent response shapes.
  • Keep pagination cursors and links intact for clients; support conditional fields with when() patterns.
  • Version resources to prevent breaking changes and allow contract evolution.

Quick Start

Instantiate a Resource collection for a model in a controller and return it to produce a stable, paginated API response.

Frequently Asked Questions about laravel-api-resources-and-pagination

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

FAQPage Schema
How do I keep Laravel pagination metadata intact when transforming models with API Resources?

Use Laravel API Resources to shape models into consistent response shapes while preserving pagination cursors and links. This approach keeps transport concerns out of Eloquent and ensures clients receive stable, paginated API responses with intact navigation metadata.

How do I conditionally include relationship fields in a Laravel API response?

Use the whenLoaded pattern within your Laravel API Resources to support conditional fields. This prevents loading unnecessary relationships, ensuring your API response only includes related data when it is explicitly loaded and requested by the endpoint.

What is the best way to version Laravel API Resources to prevent breaking changes?

Version your Laravel API Resources to allow contract evolution and prevent breaking changes. This approach enforces versioned contracts across multiple endpoints, letting you deliver stable response shapes while iteratively updating your API structure safely.

Why should I use API Resources instead of returning Eloquent models directly from Laravel controllers?

API Resources solve the problem of keeping transport concerns out of Eloquent. By transforming models into consistent response shapes, you ensure stable payloads, support conditional fields, and make API responses easier for clients to consume.

Can I apply Laravel API Resources to controllers returning collections with multiple relationships?

Yes, Laravel API Resources apply directly to controllers returning collections with relationships. You can instantiate a Resource collection for a model to produce a stable, paginated API response while supporting conditional fields via whenLoaded patterns.