resources/boost/skills/resources/SKILL.md
API resource classes that transform Eloquent models into JSON-ready arrays. Resources control exactly what is exposed in API responses and handle relationships, conditional attributes, and date formatting.
npx skillsauth add codebar-ag/coding-guidelines resourcesInstall 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.
app/Http/Resources/.ModelResource (for example UserResource) for single entities.UserResource::collection(...) for simple lists.ResourceCollection only when custom top-level meta is required.toArray() ContractwhenLoaded() for relationships.when(), whenHas(), whenNotNull(), and mergeWhen() for conditional fields.toArray().class UserResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'posts' => PostResource::collection($this->whenLoaded('posts')),
'secret' => $this->when($request->user()->isAdmin(), $this->secret),
'bio' => $this->whenNotNull($this->bio),
'created_at' => DateHelper::format($this->created_at),
];
}
}
// Critical: eager-load in controller before passing to resource.
return UserResource::collection(User::with('posts')->paginate());
// Dedicated collection — only when custom meta is needed
class UserCollection extends ResourceCollection
{
public function toArray(Request $request): array
{
return [
'data' => $this->collection,
'links' => ['self' => route('users.index')],
];
}
}
toArray() has no DB queries or lazy-load triggers.when* helpers.toArray() (causes N+1 query issues)if statements inside the response array instead of when(), whenLoaded(), whenNotNull()UserResource::collection())resources/boost/skills/controllers/SKILL.md (query/loading responsibilities)resources/boost/skills/helpers/SKILL.md (formatting helpers used in resources)testing
Translation and localization conventions for Laravel. Use when adding user-facing strings, creating translation files, or working with lang/ directory.
tools
Reusable behaviour shared across multiple unrelated classes. Traits provide shared Eloquent scopes, accessors, lifecycle hooks, and small stateless helper methods.
development
Tailwind CSS v4 styling conventions. Use when working with CSS, Tailwind utilities, or customizing the theme in Laravel projects.
development
Orchestration classes that coordinate multiple Actions, external APIs, or domain operations into a cohesive workflow. Services own transaction boundaries and third-party API integrations.