Back to skills
SKILL.md
Laravel Api Resources And Pagination
ASecurityRepresent models via Resources; keep transport concerns out of Eloquent.
- 67 stars
- 0 votes
- 0 copies
- 3 views
- Added November 10, 2026
Works with
Security analysis
100/100npx -y skills add ComeOnOliver/skillshub --skill laravel-api-resources-and-pagination --agent claude-codeAre you the author of Laravel Api Resources And Pagination?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/comeonoliver-laravel-api-resources-and-pagination)# 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
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.