plugins/laravel-expert/skills/laravel-jsonapi/SKILL.md
Use when building JSON:API compliant endpoints in Laravel 13 using the first-party `JsonApiResource` base class. Covers sparse fieldsets, inclusion, links, and response headers.
npx skillsauth add fusengine/agents laravel-jsonapiInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
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 latterdevelopment
Use when optimizing entity-based / semantic SEO 2026. Covers entity maps, Google Knowledge Graph resolution, salience scoring, passage-level ranking, about/sameAs/knowsAbout schema, Cloud Natural Language API validation.
development
Use when running SEO, GEO, schema, Core Web Vitals, sitemap, hreflang, E-E-A-T, AI Overviews, technical SEO, or structured data tasks. Covers full-site audits, single-page analysis, schema markup, content quality, AI search optimization, local SEO, sitemap/robots, internal linking, semantic clustering, and search experience.
development
Use when optimizing search experience (SXO). Covers intent matching, user personas, user stories, page-type analysis, dwell time, scroll depth, pogo-sticking prevention.
development
Use when optimizing local SEO. Covers Google Business Profile, NAP consistency, citations, reviews acquisition, Local Pack ranking, location pages, LocalBusiness schema.