Skillshub laravel-api
REST and JSON API standards for modern Laravel backends. Use when designing REST endpoints, API resources, or JSON API responses in Laravel. (triggers: routes/api.php, app/Http/Resources/**/*.php, resource, collection, sanctum, passport, cors)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/laravel-api" ~/.claude/skills/comeonoliver-skillshub-laravel-api && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/laravel-api/SKILL.mdsource content
Laravel API
Priority: P1 (HIGH)
Structure
app/ └── Http/ ├── Resources/ # Data transformation └── Controllers/ └── Api/ # API specific logic
Implementation Guidelines
API Resources & Transformation
- API Resources: Always use
classes extendingApiResource
for data transformation.JsonResource - Collections: Use
for lists. Never useUserResource::collection($users)
or return raw models directly.response()->json($model) - Data Definition: Implement
to define specific output fields and prevent sensitive data leakage.toArray($request) - Generation: Use
to scaffold new resources.php artisan make:resource UserResource
Authentication & Security
- Sanctum: Use
middleware inauth:sanctum
for SPAs or mobile app authentication.routes/api.php - Traits: Add the
trait to yourHasApiTokens
model to enable token-based authentication.User - Token Management: Issue tokens using
.$user->createToken('token-name')->plainTextToken - OAuth2: Use Passport only if standard OAuth2 flows or client grants are required.
Routing & Performance
- Versioning: Group routes with
and use versioned namespaces (e.g.,Route::prefix('v1')->group(...)
).App\Http\Controllers\Api\V1 - Rate Limiting: Define
usingRateLimiter::for('api', ...)
inLimit::perMinute(60)
.AppServiceProvider - Middleware: Apply the
middleware to route groups inthrottle:api
.routes/api.php - Status Codes: Return 201 for Created, 422 for Validation errors, and 204 for No Content.
Anti-Patterns
- No raw model returns: Use API Resources; prevents data leakage.
- No
: Use API Resource classes instead.response()->json() - No session auth for APIs: Use Sanctum or Passport tokens.
- No static URLs in JSON: Use route names or HATEOAS links.