Use a `JsonResource` to define the public representation and its collection helper for lists: ```bash php artisan make:resource UserResource ``` ```php class UserResource extends JsonResource { public function toArray($request): array { return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, 'links' => ['self' => route('users.show', $this->resource)], ]; } } ``` Return one model as `new UserResource($user)` and a list as `UserResource::collection($users)`. The resource sho...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill laravel-api --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Laravel Api?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-laravel-api-098e9be2)More formats (shields.io, HTML) on the badges page.
Use a `JsonResource` to define the public representation and its collection helper for lists:
```bash
php artisan make:resource UserResource
```
```php
class UserResource extends JsonResource
{
public function toArray($request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
'links' => ['self' => route('users.show', $this->resource)],
];
}
}
```
Return one model as `new UserResource($user)` and a list as `UserResource::collection($users)`. The resource should expose an intentional field allowlist rather than serializing the model, which prevents accidental leakage of credentials or internal columns. For paginated results, pass the paginator to the collection helper so Laravel includes pagination metadata. Keep route names stable and use named routes for links; do not return raw models or build static URLs into the JSON.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!