$npx -y skills add fusengine/agents --skill laravel-apiBuild RESTful APIs with Laravel using API Resources, Sanctum authentication, rate limiting, and versioning. Use when creating API endpoints, transforming responses, or handling API authentication.
| 1 | # Laravel API Development |
| 2 | |
| 3 | ## Agent Workflow (MANDATORY) |
| 4 | |
| 5 | Before ANY implementation, use `TeamCreate` to spawn 3 agents: |
| 6 | |
| 7 | 1. **fuse-ai-pilot:explore-codebase** - Analyze existing API patterns |
| 8 | 2. **fuse-ai-pilot:research-expert** - Verify Laravel API docs via Context7 |
| 9 | 3. **mcp__context7__query-docs** - Check API Resources and Sanctum patterns |
| 10 | |
| 11 | After implementation, run **fuse-ai-pilot:sniper** for validation. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## Overview |
| 16 | |
| 17 | Build RESTful APIs with Laravel using API Resources for response transformation and Sanctum for authentication. |
| 18 | |
| 19 | | Component | Purpose | |
| 20 | |-----------|---------| |
| 21 | | **Controllers** | Handle requests, delegate to services | |
| 22 | | **Form Requests** | Validate input, authorize actions | |
| 23 | | **API Resources** | Transform models to JSON | |
| 24 | | **Middleware** | Auth, rate limiting, CORS | |
| 25 | | **Routes** | Versioned endpoints with groups | |
| 26 | | **Pagination** | Offset/cursor pagination | |
| 27 | | **HTTP Client** | Consume external APIs | |
| 28 | |
| 29 | --- |
| 30 | |
| 31 | ## Critical Rules |
| 32 | |
| 33 | 1. **Always use API Resources** - Never return Eloquent models directly |
| 34 | 2. **Versioned routes** - Prefix with `/v1/`, `/v2/` |
| 35 | 3. **Validate all input** - Use Form Requests, not inline validation |
| 36 | 4. **Rate limiting** - Configure per-route limits |
| 37 | 5. **Consistent responses** - Same structure, proper status codes |
| 38 | 6. **Use services** - Keep controllers thin |
| 39 | 7. **Eager load** - Prevent N+1 with `with()` before pagination |
| 40 | |
| 41 | --- |
| 42 | |
| 43 | ## Reference Guide |
| 44 | |
| 45 | ### Core Concepts |
| 46 | |
| 47 | | Topic | Reference | When to consult | |
| 48 | |-------|-----------|-----------------| |
| 49 | | **Routing** | [routing.md](references/routing.md) | Defining versioned API routes | |
| 50 | | **Controllers** | [controllers.md](references/controllers.md) | Controller patterns, resource methods | |
| 51 | | **Middleware** | [middleware.md](references/middleware.md) | Route protection, request filtering | |
| 52 | | **Validation** | [validation.md](references/validation.md) | Form Requests, validation rules | |
| 53 | |
| 54 | ### Request/Response |
| 55 | |
| 56 | | Topic | Reference | When to consult | |
| 57 | |-------|-----------|-----------------| |
| 58 | | **Requests** | [requests.md](references/requests.md) | Accessing input, files, headers | |
| 59 | | **Responses** | [responses.md](references/responses.md) | API Resources, status codes | |
| 60 | | **Pagination** | [pagination.md](references/pagination.md) | Offset/cursor pagination | |
| 61 | |
| 62 | ### Advanced |
| 63 | |
| 64 | | Topic | Reference | When to consult | |
| 65 | |-------|-----------|-----------------| |
| 66 | | **Rate Limiting** | [rate-limiting.md](references/rate-limiting.md) | Throttle configuration | |
| 67 | | **HTTP Client** | [http-client.md](references/http-client.md) | Consuming external APIs | |
| 68 | | **URLs** | [urls.md](references/urls.md) | URL generation, signed URLs | |
| 69 | | **Strings** | [strings.md](references/strings.md) | String helpers, UUIDs, slugs | |
| 70 | | **Redirects** | [redirects.md](references/redirects.md) | Redirect responses | |
| 71 | |
| 72 | --- |
| 73 | |
| 74 | ### Templates (Code Examples) |
| 75 | |
| 76 | #### Controllers & Routes |
| 77 | |
| 78 | | Template | Purpose | |
| 79 | |----------|---------| |
| 80 | | [ApiController.php.md](references/templates/ApiController.php.md) | Complete CRUD controller with service | |
| 81 | | [api-routes.md](references/templates/api-routes.md) | Versioned routes with middleware | |
| 82 | | [routing-examples.md](references/templates/routing-examples.md) | Detailed routing patterns | |
| 83 | |
| 84 | #### Validation & Resources |
| 85 | |
| 86 | | Template | Purpose | |
| 87 | |----------|---------| |
| 88 | | [FormRequest.php.md](references/templates/FormRequest.php.md) | Store/Update Form Requests | |
| 89 | | [validation-rules.md](references/templates/validation-rules.md) | All validation rules reference | |
| 90 | | [ApiResource.php.md](references/templates/ApiResource.php.md) | Resource with relationships | |
| 91 | |
| 92 | #### External APIs |
| 93 | |
| 94 | | Template | Purpose | |
| 95 | |----------|---------| |
| 96 | | [HttpClientService.php.md](references/templates/HttpClientService.php.md) | Reusable HTTP client service | |
| 97 | |
| 98 | --- |
| 99 | |
| 100 | ## Quick Reference |
| 101 | |
| 102 | ### Resource Response |
| 103 | |
| 104 | ```php |
| 105 | return PostResource::collection($posts); |
| 106 | return PostResource::make($post); |
| 107 | ``` |
| 108 | |
| 109 | ### Status Codes |
| 110 | |
| 111 | ```php |
| 112 | return PostResource::make($post)->response()->setStatusCode(201); |
| 113 | return response()->json(null, 204); |
| 114 | ``` |
| 115 | |
| 116 | ### Form Request |
| 117 | |
| 118 | ```php |
| 119 | public function store(StorePostRequest $request): JsonResponse |
| 120 | { |
| 121 | $post = $this->service->create($request->validated()); |
| 122 | return PostResource::make($post)->response()->setStatusCode(201); |
| 123 | } |
| 124 | ``` |
| 125 | |
| 126 | ### Rate Limiting |
| 127 | |
| 128 | ```php |
| 129 | Route::middleware('throttle:60,1')->group(fn () => . |