← Back to the catalog

Skill · Version 1.0.0

Laravel API and Inertia

Creates deliberate response contracts and efficient Inertia page data without exposing raw models or unnecessary relationships.

laravel-api-inertia

See how it helps

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, loaded relationships and pagination metadata.
  • Distinguishes JSON API validation responses from Inertia redirects and session errors exposed through page props.
  • Checks that invalid forms retain input, isolate errors and produce no success or mutation before a corrected retry.

Try asking this

Build an order API and Inertia form. Verify API validation and Inertia form errors separately, then correct and resubmit without losing input. 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.

Details…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, 201 on creation, 204 on empty delete, 401, 403, 404, 422 for validation, 409 for 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 successful Inertia mutations, redirect (to_route(...) or back()) with appropriate flash feedback. For validation failures, Laravel redirects back with session errors; the adapter exposes them through page.props.errors, triggering onError instead of onSuccess. A JSON API's 422 response is a separate contract, not the Inertia form-validation flow.
  • Preserve submitted field state on validation failure. Use the form helper's scoped errors, or named error bags for multiple forms that share field names. Verify an invalid submission retains input, displays errors only on the submitted form, and produces no success feedback or mutation; then correct and resubmit successfully.

Included files 2

  • LICENSE.txt
  • SKILL.md

About this skill package

laravel-api-inertia

laravel-api-inertia: Build and maintain Laravel applications with consistent Eloquent models, queues, authorization and tested upgrades.

Details…Show less

laravel-api-inertia

laravel-api-inertia: Build and maintain Laravel applications with consistent Eloquent models, queues, authorization and tested upgrades.

Includes the complete skill and its supporting files (2 files). The exact authored scope is preserved below.

Original skill description (source language)

Use when building or reviewing Laravel API endpoints, JsonResource classes, pagination and error responses, or Inertia.js responses, shared props, partial reloads, deferred props and form validation contracts.

Install the skill, review its source and trust settings, then enable it for the relevant project or agent.

Requirements

  • Orqestria installed on your computer.