From superpowers-laravel
Implements Laravel API Resources with pagination, conditional fields via when(), and stable response shapes for cache-friendly APIs. Useful for consistent model serialization in controllers.
How this skill is triggered — by the user, by Claude, or both
Slash command
/superpowers-laravel:api-resources-and-paginationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Represent models via Resources; keep transport concerns out of Eloquent.
Represent models via Resources; keep transport concerns out of Eloquent.
# 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(),
];
}
Resource::collection($query->paginate()) over manual arrayswhen() / mergeWhen() for conditional fieldsnpx claudepluginhub jpcaparas/superpowers-laravel --plugin superpowers-laravelProvides patterns for Laravel API Resources covering transformation, conditional attributes, nested relationships, collections, and pagination links. Use for standardizing JSON API responses.
Build RESTful APIs with Laravel using API Resources, Sanctum authentication, rate limiting, and versioning. Use when creating API endpoints, transforming responses, or handling API authentication.
Provides Laravel patterns for controllers, services, Eloquent ORM, routing, queues, events, caching, and API resources in production apps.