Agent skill
laravel-api
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.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/laravel-api
SKILL.md
Laravel API Development
Agent Workflow (MANDATORY)
Before ANY implementation, launch in parallel:
- fuse-ai-pilot:explore-codebase - Analyze existing API patterns
- fuse-ai-pilot:research-expert - Verify Laravel API docs via Context7
- mcp__context7__query-docs - Check API Resources and Sanctum patterns
After implementation, run fuse-ai-pilot:sniper for validation.
Overview
Build RESTful APIs with Laravel using API Resources for response transformation and Sanctum for authentication.
| Component | Purpose |
|---|---|
| Controllers | Handle requests, delegate to services |
| Form Requests | Validate input, authorize actions |
| API Resources | Transform models to JSON |
| Middleware | Auth, rate limiting, CORS |
| Routes | Versioned endpoints with groups |
| Pagination | Offset/cursor pagination |
| HTTP Client | Consume external APIs |
Critical Rules
- Always use API Resources - Never return Eloquent models directly
- Versioned routes - Prefix with
/v1/,/v2/ - Validate all input - Use Form Requests, not inline validation
- Rate limiting - Configure per-route limits
- Consistent responses - Same structure, proper status codes
- Use services - Keep controllers thin
- Eager load - Prevent N+1 with
with()before pagination
Reference Guide
Core Concepts
| Topic | Reference | When to consult |
|---|---|---|
| Routing | routing.md | Defining versioned API routes |
| Controllers | controllers.md | Controller patterns, resource methods |
| Middleware | middleware.md | Route protection, request filtering |
| Validation | validation.md | Form Requests, validation rules |
Request/Response
| Topic | Reference | When to consult |
|---|---|---|
| Requests | requests.md | Accessing input, files, headers |
| Responses | responses.md | API Resources, status codes |
| Pagination | pagination.md | Offset/cursor pagination |
Advanced
| Topic | Reference | When to consult |
|---|---|---|
| Rate Limiting | rate-limiting.md | Throttle configuration |
| HTTP Client | http-client.md | Consuming external APIs |
| URLs | urls.md | URL generation, signed URLs |
| Strings | strings.md | String helpers, UUIDs, slugs |
| Redirects | redirects.md | Redirect responses |
Templates (Code Examples)
Controllers & Routes
| Template | Purpose |
|---|---|
| ApiController.php.md | Complete CRUD controller with service |
| api-routes.md | Versioned routes with middleware |
| routing-examples.md | Detailed routing patterns |
Validation & Resources
| Template | Purpose |
|---|---|
| FormRequest.php.md | Store/Update Form Requests |
| validation-rules.md | All validation rules reference |
| ApiResource.php.md | Resource with relationships |
External APIs
| Template | Purpose |
|---|---|
| HttpClientService.php.md | Reusable HTTP client service |
Quick Reference
Resource Response
return PostResource::collection($posts);
return PostResource::make($post);
Status Codes
return PostResource::make($post)->response()->setStatusCode(201);
return response()->json(null, 204);
Form Request
public function store(StorePostRequest $request): JsonResponse
{
$post = $this->service->create($request->validated());
return PostResource::make($post)->response()->setStatusCode(201);
}
Rate Limiting
Route::middleware('throttle:60,1')->group(fn () => ...);
Versioned Routes
Route::prefix('v1')->group(function () {
Route::apiResource('posts', PostController::class);
});
Pagination
return PostResource::collection(Post::paginate(15));
Feature Matrix
| Feature | Status | Reference |
|---|---|---|
| RESTful Controllers | ✅ | controllers.md |
| API Resources | ✅ | responses.md |
| Form Request Validation | ✅ | validation.md |
| Route Versioning | ✅ | routing.md |
| Route Model Binding | ✅ | routing.md |
| Middleware | ✅ | middleware.md |
| Rate Limiting | ✅ | rate-limiting.md |
| Pagination | ✅ | pagination.md |
| Cursor Pagination | ✅ | pagination.md |
| HTTP Client | ✅ | http-client.md |
| Signed URLs | ✅ | urls.md |
| JSON Responses | ✅ | responses.md |
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?