Skip to content
Back to skills

Laravel Inertia React

ASecurity

Laravel + Inertia.js + React integration patterns. Use when building Inertia page components, handling forms with useForm, managing shared data, or implementing persistent layouts. Triggers on tasks involving Inertia.js, page props, form handling, or Laravel React integration. Not for Laravel for Rust apps (laravel-rust crate).

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
developmentjavascripttypescriptrustgojavaphpshellreactnodegit

Works with

  • cli

Security analysis

A100/100

Pro scans all 19 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add airshell/laravel-php-to-rust --skill laravel-inertia-react --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Laravel Inertia React?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Laravel Inertia React
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-laravel-inertia-react/badge)](https://www.skillsdirectory.com/skills/airshell-laravel-inertia-react)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: laravel-inertia-react
description: Laravel + Inertia.js + React integration patterns. Use when building Inertia page components, handling forms with useForm, managing shared data, or implementing persistent layouts. Triggers on tasks involving Inertia.js, page props, form handling, or Laravel React integration. Not for Laravel for Rust apps (laravel-rust crate).
license: MIT
metadata:
  author: airshell
  version: "1.1.1"
  laravelVersion: "13.x"
  phpVersion: "8.3+"
---

# Laravel + Inertia.js + React

Comprehensive patterns for building modern monolithic applications with Laravel, Inertia.js, and React. Contains 27 rules across 5 categories, written for Inertia v3.

## When to Apply

Reference these guidelines when:
- Creating Inertia page components
- Handling forms with useForm hook
- Managing shared data and authentication
- Implementing persistent layouts
- Navigating between pages

**Not for Laravel for Rust.** If the project is a Laravel for Rust app (its `Cargo.toml` depends on the `laravel-rust` crate), do not use this skill. The app uses the same `@inertiajs/react` package, but this skill assumes a PHP backend. Use the `inertia-frontend` skill the app ships in `.agents/skills/` and the version-matched docs bundled with the crate.

## Rule Categories by Priority

| Priority | Category | Impact | Prefix | Rules |
|----------|----------|--------|--------|-------|
| 1 | Page Components | CRITICAL | `page-` | 7 |
| 2 | Forms & Validation | CRITICAL | `form-` | 9 |
| 3 | Navigation | HIGH | `nav-` | 6 |
| 4 | Shared Data | HIGH | `shared-` | 4 |
| 5 | Layouts | MEDIUM | `layout-` | 1 |

## Quick Reference

### 1. Page Components (CRITICAL)

- `page-component-structure` - Standard page component pattern
- `page-props-typing` - Type page props from Laravel
- `page-head-management` - Title and meta tags with Head
- `page-default-layout` - Assign layouts to pages
- `page-scroll-preservation` - Keep scroll position across visits
- `page-partial-reloads` - Reload only the props that changed, `usePoll`
- `page-deferred-props` - `Inertia::defer()` with `<Deferred>`

### 2. Forms & Validation (CRITICAL)

- `form-useform-basic` - Basic useForm usage
- `form-useform-hook` - useForm methods and state
- `form-component` - `<Form>` component for simple forms
- `form-validation-errors` - Display Laravel validation errors
- `form-file-uploads` - File uploads with useForm
- `form-progress-indicator` - Upload and submit progress
- `form-transform-data` - Transform data before submit
- `form-reset-handling` - Reset fields and errors
- `form-dirty-tracking` - Track and warn on unsaved changes

### 3. Navigation (HIGH)

- `nav-link-component` - Use Link for navigation
- `nav-programmatic` - Navigate with the router
- `nav-external-links` - External links and downloads
- `nav-preserve-state` - Preserve scroll and state
- `nav-replace-history` - Replace vs push history
- `nav-usehttp-requests` - `useHttp` for JSON requests that are not page visits

### 4. Shared Data (HIGH)

- `shared-auth-user` - Access authenticated user
- `shared-flash-messages` - Handle flash messages
- `shared-ziggy-routes` - Named routes in JavaScript (Ziggy, or Wayfinder in starter-kit apps)
- `shared-app-config` - App configuration and feature flags

### 5. Layouts (MEDIUM)

- `layout-persistent` - Persistent, nested and default layouts, layout props

## Inertia v3 Notes

Check these when a project moves from Inertia v2 to v3 (see the [v3 upgrade guide](https://inertiajs.com/docs/v3/getting-started/upgrade-guide)):

- Requires PHP 8.2+, Laravel 11+ and React 19.
- Axios is no longer shipped or required; Inertia has its own HTTP client. Use `useHttp` for non-visit requests. `qs` and `lodash-es` are no longer bundled: install them yourself if the app imports them.
- `Inertia::lazy()` and `LazyProp` are removed: use `Inertia::optional()`.
- `router.cancel()` is now `router.cancelAll()`.
- The `invalid` event is now `httpException` and `exception` is now `networkError`.
- `hideProgress()` / `revealProgress()` are removed: use `progress.hide()` / `progress.reveal()` from `@inertiajs/react`.
- The `inertia` attribute on head elements is now `data-inertia`.
- The initial page data is always in a `<script type="application/json">` element; the `data-page` attribute on the root `div` is gone. Delete the `future` block from `createInertiaApp`.
- Arrow-function components assigned to `.layout` must be wrapped in an array: `Page.layout = [Layout]`.
- `<Deferred>` keeps existing content during partial reloads; use its `reloading` slot prop.
- `useForm` `processing` and `progress` reset only in `onFinish`.
- Packages are ESM-only and target ES2022.
- Republish the config and clear views: `php artisan vendor:publish --provider="Inertia\\ServiceProvider" --force` then `php artisan view:clear`.

## Essential Patterns

### Page Component with TypeScript

```tsx
// resources/js/Pages/Posts/Index.tsx
import { Head, Link } from '@inertiajs/react'

interface Post {
  id: number
  title: string
  excerpt: string
  created_at: string
  author: {
    id: number
    name: string
  }
}

interface Props {
  posts: {
    data: Post[]
    links: { url: string | null; label: string; active: boolean }[]
  }
  filters: {
    search?: string
  }
}

export default function Index({ posts, filters }: Props) {
  return (
    <>
      <Head title="Posts" />

      <div className="container mx-auto py-8">
        <h1 className="text-2xl font-bold mb-6">Posts</h1>

        <div className="space-y-4">
          {posts.data.map((post) => (
            <article key={post.id} className="p-4 bg-white rounded-lg shadow">
              <Link href={route('posts.show', post.id)}>
                <h2 className="text-xl font-semibold hover:text-blue-600">
                  {post.title}
                </h2>
              </Link>
              <p className="text-gray-600 mt-2">{post.excerpt}</p>
              <p className="text-sm text-gray-400 mt-2">
                By {post.author.name}
              </p>
            </article>
          ))}
        </div>
      </div>
    </>
  )
}
```

### Form with useForm

```tsx
// resources/js/Pages/Posts/Create.tsx
import { Head, useForm, Link } from '@inertiajs/react'
import { FormEvent } from 'react'

interface Category {
  id: number
  name: string
}

interface Props {
  categories: Category[]
}

export default function Create({ categories }: Props) {
  const { data, setData, post, processing, errors, reset } = useForm({
    title: '',
    body: '',
    category_id: '',
  })

  const handleSubmit = (e: FormEvent) => {
    e.preventDefault()
    post(route('posts.store'), {
      onSuccess: () => reset(),
    })
  }

  return (
    <>
      <Head title="Create Post" />

      <form onSubmit={handleSubmit} className="max-w-2xl mx-auto py-8">
        <div className="mb-4">
          <label htmlFor="title" className="block font-medium mb-1">
            Title
          </label>
          <input
            id="title"
            type="text"
            value={data.title}
            onChange={(e) => setData('title', e.target.value)}
            className="w-full border rounded px-3 py-2"
          />
          {errors.title && (
            <p className="text-red-500 text-sm mt-1">{errors.title}</p>
          )}
        </div>

        <div className="mb-4">
          <label htmlFor="category" className="block font-medium mb-1">
            Category
          </label>
          <select
            id="category"
            value={data.category_id}
            onChange={(e) => setData('category_id', e.target.value)}
            className="w-full border rounded px-3 py-2"
          >
            <option value="">Select a category</option>
            {categories.map((category) => (
              <option key={category.id} value={category.id}>
                {category.name}
              </option>
            ))}
          </select>
          {errors.category_id && (
            <p className="text-red-500 text-sm mt-1">{errors.category_id}</p>
          )}
        </div>

        <div className="mb-4">
          <label htmlFor="body" className="block font-medium mb-1">
            Content
          </label>
          <textarea
            id="body"
            value={data.body}
            onChange={(e) => setData('body', e.target.value)}
            rows={10}
            className="w-full border rounded px-3 py-2"
          />
          {errors.body && (
            <p className="text-red-500 text-sm mt-1">{errors.body}</p>
          )}
        </div>

        <div className="flex gap-4">
          <button
            type="submit"
            disabled={processing}
            className="px-4 py-2 bg-blue-600 text-white rounded disabled:opacity-50"
          >
            {processing ? 'Creating...' : 'Create Post'}
          </button>

          <Link
            href={route('posts.index')}
            className="px-4 py-2 border rounded"
          >
            Cancel
          </Link>
        </div>
      </form>
    </>
  )
}
```

### Persistent Layout

```tsx
// resources/js/Layouts/AppLayout.tsx
import { Link, usePage } from '@inertiajs/react'
import { ReactNode } from 'react'

interface Props {
  children: ReactNode
}

export default function AppLayout({ children }: Props) {
  const { auth } = usePage().props as { auth: { user: { name: string } } }

  return (
    <div className="min-h-screen bg-gray-100">
      <nav className="bg-white shadow">
        <div className="container mx-auto px-4 py-3 flex justify-between">
          <Link href="/" className="font-bold">
            My App
          </Link>
          <span>Welcome, {auth.user.name}</span>
        </div>
      </nav>

      <main className="container mx-auto px-4 py-8">
        {children}
      </main>
    </div>
  )
}

// resources/js/Pages/Dashboard.tsx
import AppLayout from '@/Layouts/AppLayout'

export default function Dashboard() {
  return <h1>Dashboard</h1>
}

// Assign persistent layout (or set a default for all pages with
// createInertiaApp({ layout: () => AppLayout }) - see layout-persistent)
Dashboard.layout = (page: ReactNode) => <AppLayout>{page}</AppLayout>
```

### Laravel Controller

```php
<?php

namespace App\Http\Controllers;

use App\Http\Requests\StorePostRequest;
use App\Models\Post;
use App\Models\Category;
use Illuminate\Http\RedirectResponse;
use Inertia\Inertia;
use Inertia\Response;

class PostController extends Controller
{
    public function index(): Response
    {
        return Inertia::render('Posts/Index', [
            'posts' => Post::with('author:id,name')
                ->latest()
                ->paginate(10),
            'filters' => request()->only('search'),
        ]);
    }

    public function create(): Response
    {
        return Inertia::render('Posts/Create', [
            'categories' => Category::all(['id', 'name']),
        ]);
    }

    public function store(StorePostRequest $request): RedirectResponse
    {
        $post = Post::create([
            ...$request->validated(),
            'user_id' => auth()->id(),
        ]);

        return redirect()
            ->route('posts.show', $post)
            ->with('success', 'Post created successfully.');
    }

    public function show(Post $post): Response
    {
        return Inertia::render('Posts/Show', [
            'post' => $post->load('author', 'category'),
        ]);
    }
}
```

### Shared Data (HandleInertiaRequests)

```php
<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
{
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
            'auth' => [
                'user' => $request->user() ? [
                    'id' => $request->user()->id,
                    'name' => $request->user()->name,
                    'email' => $request->user()->email,
                ] : null,
            ],
            'flash' => [
                'success' => $request->session()->get('success'),
                'error' => $request->session()->get('error'),
            ],
        ]);
    }
}
```

### Flash Messages Component

```tsx
// resources/js/Components/FlashMessages.tsx
import { usePage } from '@inertiajs/react'
import { useEffect, useState } from 'react'

export default function FlashMessages() {
  const { flash } = usePage().props as {
    flash: { success?: string; error?: string }
  }
  const [visible, setVisible] = useState(false)

  useEffect(() => {
    if (flash.success || flash.error) {
      setVisible(true)
      const timer = setTimeout(() => setVisible(false), 3000)
      return () => clearTimeout(timer)
    }
  }, [flash])

  if (!visible) return null

  return (
    <div className="fixed top-4 right-4 z-50">
      {flash.success && (
        <div className="bg-green-500 text-white px-4 py-2 rounded shadow">
          {flash.success}
        </div>
      )}
      {flash.error && (
        <div className="bg-red-500 text-white px-4 py-2 rounded shadow">
          {flash.error}
        </div>
      )}
    </div>
  )
}
```

## How to Use

Read individual rule files for detailed explanations and code examples:

```
rules/form-useform-basic.md
rules/page-props-typing.md
rules/layout-persistent.md
```

## Project Structure

```
laravel-inertia-react/
├── SKILL.md                 # This file - overview and examples
├── README.md                # Quick reference guide
├── AGENTS.md                # Integration guide for AI agents
├── metadata.json            # Skill metadata and references
└── rules/
    ├── _sections.md         # Rule categories and priorities
    ├── _template.md         # Template for new rules
    ├── page-*.md            # Page component patterns (7 rules)
    ├── form-*.md            # Form handling patterns (9 rules)
    ├── nav-*.md             # Navigation patterns (6 rules)
    ├── shared-*.md          # Shared data patterns (4 rules)
    └── layout-*.md          # Layout patterns (1 rule)
```

## References

- [Inertia.js Documentation](https://inertiajs.com/) - Official Inertia.js docs
- [Laravel Documentation](https://laravel.com/docs) - Laravel framework docs
- [React Documentation](https://react.dev/) - Official React docs
- [Inertia.js v3 Upgrade Guide](https://inertiajs.com/docs/v3/getting-started/upgrade-guide) - Breaking changes from v2
- [Ziggy](https://github.com/tighten/ziggy) - Laravel route helper for JavaScript
- [Wayfinder](https://github.com/laravel/wayfinder) - Type-safe routes used by Laravel's starter kits

## License

MIT License. This skill is provided as-is for educational and development purposes.

## Metadata

- **Version**: 1.1.1
- **Last Updated**: December 2026
- **Maintainer**: Asyraf Hussin
- **Rule Count**: 27 rules across 5 categories
- **Tech Stack**: Laravel 11+ (13.x), Inertia.js 3.x, React 19+, Vite 8, TypeScript 6+

Files in this skill

  • AGENTS.md8.7 KB
  • README.md2 KB
  • SKILL.md14.7 KB
  • rules/_sections.md1.5 KB
  • rules/_template.md1.4 KB
  • rules/form-component.md3.5 KB
  • rules/form-dirty-tracking.md6.3 KB
  • rules/form-file-uploads.md7.6 KB
  • rules/form-progress-indicator.md7.3 KB
  • rules/form-reset-handling.md5.9 KB
  • rules/form-transform-data.md5.9 KB
  • rules/form-useform-basic.md5.3 KB
  • rules/form-useform-hook.md4.3 KB
  • rules/form-validation-errors.md6.3 KB
  • rules/layout-persistent.md7.7 KB
  • rules/nav-external-links.md6.3 KB
  • rules/nav-link-component.md5.8 KB
  • rules/nav-preserve-state.md6.5 KB
  • rules/nav-programmatic.md5.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.