Agent skill
laravel-api-resources-and-pagination
Use API Resources with pagination and conditional fields; keep response shapes stable and cache-friendly
Install this agent skill to your Project
npx add-skill https://github.com/noartem/skills/tree/main/skills/laravel-api-resources-and-pagination
SKILL.md
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
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
laravel-transactions-and-consistency
Wrap multi-write operations in transactions; use dispatchAfterCommit and idempotency patterns to ensure consistency
laravel-filesystem-uploads
Store and serve files via Storage; set visibility, generate URLs, and handle streaming safely
laravel-task-scheduling
Schedule tasks with safety; use withoutOverlapping, onOneServer, and visibility settings for reliable cron execution
laravel-dependencies-trim-packages
Remove unneeded Composer packages and assets to improve boot time, memory, and security surface
laravel-controller-tests
Write focused controller tests using HTTP assertions; keep heavy logic in Actions/Services and unit test them
laravel-strategy-pattern
Use the Strategy pattern to select behavior at runtime; bind multiple implementations to a shared interface
Didn't find tool you were looking for?