← Back to Laravel SaaS foundation team
See how it helps
Laravel API and Inertia
Creates deliberate response contracts and efficient Inertia page data without exposing raw models or unnecessary relationships.
laravel-api-inertia
Team members using this skill
When is it useful?
Use when Laravel endpoints or Inertia pages need predictable data, validation and navigation behavior.
What does it help you do?
- Shapes API Resources around allowed fields and loaded relationships.
- Preserves status codes and pagination metadata across responses.
- Keeps shared page props light and returns appropriate redirects after mutations.
Try asking this
Build an order list API and Inertia page with paginated resources, permission-sensitive fields and clear feedback after saving. View the same order as a salesperson and finance user. Paginated results and page props must expose only permitted fields, including after a partial reload.
Detailed documentation
Read the skill’s original instructions, examples and checks in their authored language.
Show less
Laravel API & Inertia Integration
API Resources and HTTP contracts
- Transform Eloquent models through
JsonResource(ModelResource::make($model),ModelResource::collection($paginator)) rather than returning raw Eloquent models, so internal columns, hidden attributes and accidental relations never leak. - Guard every relationship and pivot attribute in
toArray()with$this->whenLoaded('relation'),$this->whenCounted('relation')and$this->whenPivotLoaded(...)so serialized resources never trigger lazy-loading N+1 queries. - Use
$this->when($condition, ...)or$this->mergeWhen(...)for role- or permission-dependent fields. - Return consistent status codes (
200,201on creation,204on empty delete,401,403,404,422for validation,409for state conflicts) and preserve pagination metadata (data,links,meta) when wrapping paginators.
Inertia.js server integration
- Render Inertia pages with
Inertia::render('Component/Name', [...])matching the project's page component conventions, passing only the fields the page needs (or wrapping models in Resources/DTOs). - Keep
HandleInertiaRequests::share()lightweight because shared props run on every request; wrap expensive or rarely needed shared data in closures so they are evaluated lazily. - Support partial reloads (
Inertia::lazy(...)/ closures) and, on Inertia v2,Inertia::defer(fn () => ...)for slow secondary panels so the initial page shell loads fast and the UI can show targeted loading skeletons. - After mutations in Inertia controllers, return a redirect (
to_route(...)orback()) with flash feedback rather than returning JSON directly, so validation errors (422->errorsprop / error bags) and Inertia'suseForm/<Form>state work seamlessly.
Included files 2
LICENSE.txtSKILL.md
