From fuse-laravel
Builds JSON:API compliant endpoints in Laravel 13 using the first-party JsonApiResource base class. Covers sparse fieldsets, inclusion, links, and response headers.
How this skill is triggered — by the user, by Claude, or both
Slash command
/fuse-laravel:laravel-jsonapiThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Before ANY implementation, use `TeamCreate` to spawn 3 agents:
Before ANY implementation, use TeamCreate to spawn 3 agents:
JsonResource classes to migratelaravel.com/docs/13.x/eloquent-resources examplesAfter implementation, run fuse-ai-pilot:sniper for validation.
| Feature | Description |
|---|---|
JsonApiResource | Base class extending JsonResource with spec compliance |
| Content-Type | Auto-sets application/vnd.api+json |
| Sparse fieldsets | ?fields[posts]=title,created_at |
| Inclusion | ?include=author,comments with included array |
| Resource identifiers | {"id":"1","type":"posts"} in relationships |
| Links | self, related links auto-generated |
JsonApiResource - Never roll your own JSON:API serializer; the base class handles spec edge cases$type - Each resource MUST set a string $type (e.g., posts, users)toAttributes() not toArray() - JSON:API splits attributes from identifiers; mixing them breaks compliancerelationships() returning only the relations clients may includeAccept: application/vnd.api+jsonapp/Http/Resources/
├── PostResource.php # extends JsonApiResource, $type = 'posts'
├── UserResource.php # extends JsonApiResource, $type = 'users'
└── CommentResource.php # extends JsonApiResource, $type = 'comments'
app/Http/Controllers/
└── Api/PostController.php # returns PostResource::collection($posts)
→ See PostResource.php.md for full example
| Topic | Reference | When to Consult |
|---|---|---|
| Base resource class | resources.md | Structuring JsonApiResource subclasses |
| Sparse fieldsets | sparse-fieldsets.md | Implementing fields[type]=a,b |
| Relationships | relationships.md | Inclusion + identifiers + links |
| Template | When to Use |
|---|---|
| PostResource.php.md | Resource with belongsTo + hasMany |
| UserResource.php.md | Simple resource with sparse fields |
use Illuminate\Http\Resources\Json\JsonApiResource;
class PostResource extends JsonApiResource
{
public string $type = 'posts';
public function toAttributes($request): array
{
return ['title' => $this->title, 'body' => $this->body];
}
}
return PostResource::collection(Post::with('author')->get());
→ See PostResource.php.md for complete example
include to avoid N+1 (?include=author → with('author'))include and fields parameters in your OpenAPI spec$type matching the URL segment (e.g., /api/posts → 'posts')toLinks() to expose self, related, pagination linksJsonApiResource base class - manual JSON breaks subtle spec rules (e.g., null vs empty data)relationships() - silent ignoring keeps APIs predictabletoArray() and toAttributes() - the JSON:API base class expects the latternpx claudepluginhub fusengine/agents --plugin fuse-laravelProvides patterns for Laravel API Resources covering transformation, conditional attributes, nested relationships, collections, and pagination links. Use for standardizing JSON API responses.
Represents Eloquent models via API Resources with pagination and conditional fields. Covers plain Resources and Laravel 13+ first-party JSON:API Resources.
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.