Skip to content
Back to skills

Api Resources And Pagination

ASecurity

Use API Resources with pagination and conditional fields; keep response shapes stable and cache-friendly

  • 147 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 6, 2026
toolsphpapi

Works with

  • cursor
  • cli
  • api

Security analysis

A100/100

Scanned June 6, 2026

npx -y skills add jpcaparas/superpowers-laravel --skill api-resources-and-pagination --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Api Resources And Pagination?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Api Resources And Pagination
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/jpcaparas-api-resources-and-pagination/badge)](https://www.skillsdirectory.com/skills/jpcaparas-api-resources-and-pagination)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel:api-resources-and-pagination
description: Use API Resources with pagination and conditional fields; keep response shapes stable and cache-friendly
---

# 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

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.