laravel:api-resources-and-pagination

API Resources and Pagination

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "laravel:api-resources-and-pagination" with this command: npx skills add jpcaparas/superpowers-laravel/jpcaparas-superpowers-laravel-laravel-api-resources-and-pagination

API Resources and Pagination

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

Commands

Resource

sail 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

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

laravel:routes-best-practices

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:blade-components-and-layouts

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:queues-and-horizon

No summary provided by upstream source.

Repository SourceNeeds Review
General

laravel:quality-checks

No summary provided by upstream source.

Repository SourceNeeds Review