mcpField
L
laravel-api-resources-and-pagination

laravel-api-resources-and-pagination

github.com/noartemDevelopment1377 installsUpdated 3w ago
Repository

About laravel-api-resources-and-pagination

A skill for Laravel developers that covers representing models with API Resources and handling pagination. It emphasizes preserving pagination metadata for clients and managing resource contract changes.

Key features

  1. 01Return models through Resource collections
  2. 02Add conditional fields
  3. 03Preserve pagination links and cursors
  4. 04Version resource contracts

Use cases

  1. 01Build paginated API responses
  2. 02Return fields conditionally
  3. 03Evolve API resource contracts

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/noartem/skills --skill laravel-api-resources-and-pagination

After installing, type/laravel-api-resources-and-paginationin Claude Code to confirm it loaded.

Details

From the project README

API Resources and Pagination

Represent models via Resources; keep transport concerns out of Eloquent.

Commands

# Resource
php artisan make:resource PostResource    # or: php artisan make:resource PostResource

# Controller usage
return PostResource::collection(
    Post::with('author')->latest()->paginate(20)
);

# Resource class
public function toArray($request)
{
    return [
        'id' => $this->id,
        'title' => $this->title,
        'author' => new UserResource($this->whenLoaded('author')),
        'published_at' => optional($this->published_at)->toAtomString(),
    ];
}

Patterns

  • Prefer Resource::collection($query->paginate()) over manual arrays
  • Use when() / mergeWhen() for conditional fields
  • Keep pagination cursors/links intact for clients
  • Version resources when contracts change; avoid breaking fields silently

Comments

Markdown supported