Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

Laravel Livewire: Build Interactive UIs Without Writing JavaScript (2026)

Most Laravel apps need the same thing sooner or later: a search box that filters as you type, a form that validates without a page reload, a table with working pagination, a file upload with a preview. The standard answer is to reach for a JavaScript framework, build an API, and maintain two codebases that drift apart. Laravel Livewire exists so you can skip all of that. It lets you build dynamic, reactive interfaces using only PHP and Blade — Livewire handles the JavaScript behind the scenes — and with Livewire 4, released 14 January 2026, the framework got its biggest overhaul yet: single-file components, islands, and a new rendering engine. This guide builds a real feature with it, the way you would in a production app. Verified 18 November 2026 against the official Livewire documentation and the Laravel News Livewire 4 release coverage; all code samples target Livewire 4 on Laravel 13.x.

What Laravel Livewire Is (and What Changed in Livewire 4)

A Livewire component is a PHP class paired with a Blade template. You declare public properties on the class, bind them to inputs with wire:model, and call methods with wire:click or wire:submit. When a user interacts with the page, Livewire sends a small request to the server, runs your PHP, and swaps only the changed HTML — no full page reload, no API endpoint, no JavaScript written by you.

Livewire 4, released 14 January 2026, is the biggest release in the framework’s history, and it changes how components are written:

  • Single-file components are the default. PHP logic, Blade markup, scoped CSS and component JavaScript now live in one .blade.php file, marked with a ⚡ in the filename. The old class-plus-view format still works — existing v3 components need no changes — and you can still generate it with --mfc.
  • Islands isolate expensive regions. Wrap part of a component in @island and only that region re-renders when it updates, instead of the whole component.
  • Routing is simpler. Route::livewire() registers a component as a full page, replacing the old Route::get() plus component dance.
  • Built-in drag-and-drop sorting with wire:sort — no external library.
  • Optimistic UI directives update the page instantly on the client, before the server round-trip finishes.
  • Blaze, a new rendering engine, pre-compiles the static parts of your templates. In Caleb Porzio’s Laracon US 2025 demo, one component’s render time dropped from 329ms to 19ms.

If you have used Livewire 3, the mental model is unchanged — the same directives, the same request cycle. Version 4 mostly removes friction: fewer files, fewer re-renders, fewer reasons to reach for JavaScript.

Install Livewire and Build Your First Component

Livewire 4 needs Laravel 10 or later and PHP 8.1 or later. Install it with one Composer command:

composer require livewire/livewire

Next, generate the layout your components will render inside:

php artisan livewire:layout

This creates resources/views/layouts/app.blade.php with the @livewireStyles and @livewireScripts directives that load Livewire’s assets. If those two directives are missing, nothing works — it is the first thing to check when a component silently does nothing.

Now create your first component. This one is a full page, so use the pages:: prefix to keep it organised:

php artisan make:livewire pages::post.create

That generates a single-file component at resources/views/pages/post/⚡create.blade.php. The ⚡ is just a Unicode character in the filename — it makes Livewire components instantly recognisable in your editor, and you can disable it in config if you prefer. Open the file and replace its contents with a working form:

<?php

use Livewire\Component;

new class extends Component {
    public string $title = '';
    public string $content = '';

    public function save()
    {
        $this->validate([
            'title' => 'required|max:255',
            'content' => 'required',
        ]);

        Post::create([
            'title' => $this->title,
            'content' => $this->content,
        ]);

        return $this->redirect('/posts');
    }
};

?>

<form wire:submit="save">
    <label>
        Title
        <input type="text" wire:model="title">
        @error('title') <span>{{ $message }}</span> @enderror
    </label>

    <label>
        Content
        <textarea wire:model="content" rows="5"></textarea>
        @error('content') <span>{{ $message }}</span> @enderror
    </label>

    <button type="submit">Save Post</button>
</form>

Three things are doing the work here. wire:model="title" binds the input to the $title property — by default the value is sent to the server when the form is submitted, so typing fires no network requests at all. wire:submit="save" calls the save() method instead of reloading the page. And $this->validate() runs Laravel’s normal validation rules, with errors shown by the familiar @error directive.

Register the route in routes/web.php:

Route::livewire('/post/create', 'pages::post.create');

Visit /post/create, submit the form empty, and the validation errors appear without a page reload. That is the whole pitch: a reactive form, zero JavaScript, and every line of it is PHP and Blade you already know.

One rule to memorise early: a component must have exactly one root HTML element. In the example above the <form> is the root. Multiple roots, or stray HTML comments outside the root, will error.

Forms and Validation: The 80% Use Case

Forms are where Livewire earns its keep, and the framework gives you three levels of control over when data reaches the server.

Plain wire:model is deferred: the value syncs when the next request happens, usually the form submit. That is the right default for most forms — it keeps network traffic at zero while the user types. When you do want live feedback, add modifiers:

<!-- Updates the server on every keystroke -->
<input type="text" wire:model.live="search">

<!-- Updates when the field loses focus -->
<input type="text" wire:model.live.blur="email">

<!-- Updates on keystroke, but at most once per 150ms -->
<input type="text" wire:model.live.debounce.150ms="search">

<!-- Updates at most once per 150ms while typing -->
<input type="text" wire:model.live.throttle.150ms="search">

Reach for .debounce on search fields and .blur on fields that trigger expensive validation. Bare .live on a text input fires a request per keystroke, which is how a simple search box turns into a denial-of-service attack on your own server.

For validation, prefer the #[Validate] attribute over inline rules. Rules declared on the property run every time that property is updated server-side, so errors appear as the user types instead of only on submit:

use Livewire\Attributes\Validate;
use Livewire\Component;

new class extends Component {
    #[Validate('required|min:5')]
    public $title = '';

    #[Validate('required|email')]
    public $email = '';

    public function save()
    {
        $this->validate();
        // ...
    }
};

When a form grows past a handful of fields, extract it into a form object. Livewire generates one for you:

php artisan livewire:form PostForm

The form class holds the properties, the #[Validate] rules, and the store()/update() methods, while the component stays thin. It is the same pattern as a form request in a controller, and it keeps a 15-field admin form from turning your component into a wall of properties. Two helpers are worth knowing: $this->reset() clears the form after a successful submit, and $this->pull() retrieves the values and resets them in one call.

Build a Live Search with Pagination

Live search plus pagination is the feature that sells Livewire to most teams, because in a traditional Laravel app it means an API endpoint, a JavaScript framework, and keeping the two in sync. In Livewire it is one component.

<?php // resources/views/components/⚡search-posts.blade.php

use Livewire\Attributes\Computed;
use Livewire\WithPagination;
use Livewire\Component;
use App\Models\Post;

new class extends Component {
    use WithPagination;

    public $query = '';

    public function search()
    {
        $this->resetPage();
    }

    #[Computed]
    public function posts()
    {
        return Post::where('title', 'like', '%'.$this->query.'%')
            ->paginate(10);
    }
};

?>

<div>
    <form wire:submit="search">
        <input type="text" wire:model.live.debounce.250ms="query" placeholder="Search posts...">
        <button type="submit">Search</button>
    </form>

    <div>
        @foreach ($this->posts as $post)
            <article wire:key="{{ $post->id }}">
                <h3>{{ $post->title }}</h3>
            </article>
        @endforeach
    </div>

    {{ $this->posts->links() }}
</div>

Four details make this work properly:

  • WithPagination is a trait — add it and pagination just works inside the component, including updating the ?page=2 query string in the URL as the user navigates.
  • #[Computed] memoises the query for the duration of the request, so the same query is not re-run every time the template touches $this->posts. Put expensive queries in computed properties, never in render().
  • $this->resetPage() sends the user back to page 1 when the search changes. Forget it and users land on an empty page 5 of a two-page result set — the most common Livewire pagination bug.
  • wire:key on each loop item tells Livewire which DOM element belongs to which record. Without it, reordering or filtering a list can scramble the wrong rows.

If you do not want the page number in the URL, add the WithoutUrlPagination trait alongside WithPagination. And if the page jumps to the top on every page change, pass scrollTo: false to links() — or a CSS selector to scroll to a specific element instead.

File Uploads Without the Boilerplate

File uploads are the feature most developers assume needs a JavaScript library. In Livewire they need a trait and a wire:model on a file input:

<?php // resources/views/components/⚡upload-photo.blade.php

use Livewire\Attributes\Validate;
use Livewire\WithFileUploads;
use Livewire\Component;

new class extends Component {
    use WithFileUploads;

    #[Validate('image|max:1024')] // 1MB max
    public $photo;

    public function save()
    {
        $this->validate();

        $this->photo->store(path: 'photos');
    }
};

?>

<form wire:submit="save">
    @if ($photo)
        <img src="{{ $photo->temporaryUrl() }}">
    @endif

    <input type="file" wire:model="photo">
    @error('photo') <span>{{ $message }}</span> @enderror

    <button type="submit">Save photo</button>
</form>

Behind the scenes, Livewire requests a signed temporary upload URL, uploads the file to a livewire-tmp/ directory, and sets your property to the temporary file — the same store() and storeAs() APIs you already use in controllers work unchanged. temporaryUrl() gives you an instant image preview before the form is submitted (images only, for security), and the livewire-upload-progress JavaScript event lets you wire a progress bar with a few lines of Alpine.

Three gotchas to know. First, never name a method or property upload — the name is reserved by Livewire and will break your component. Second, if you store uploads on S3, set LIVEWIRE_TEMPORARY_FILE_UPLOAD_DISK=s3 in your .env so temporary files go straight to the bucket instead of through your server, then run php artisan livewire:configure-s3-upload-cleanup so S3 deletes temporary files older than 24 hours. Third, multiple files work the same way: add the multiple attribute and use an array property with a photos.* validation rule.

Make It Feel Like an SPA: wire:navigate, Lazy Loading, and Islands

Livewire’s biggest complaint has always been that every interaction is a server round-trip, so pages feel slower than a JavaScript SPA. Three features in the current version close most of that gap.

wire:navigate turns a multi-page app into an SPA. Add the attribute to a link and Livewire fetches the next page in the background and swaps the URL, title and body — no full reload, no re-downloading your CSS and JavaScript. It even prefetches: pressing the mouse button down starts the request, so by the time the click completes, half the page is already loaded. Add .hover and it prefetches after 60 milliseconds of hovering. Redirects can use it too with $this->redirect('/posts', navigate: true), and @persist keeps an element — an audio player, for example — alive across page visits.

<nav>
    <a href="/" wire:navigate>Dashboard</a>
    <a href="/posts" wire:navigate>Posts</a>
    <a href="/users" wire:navigate>Users</a>
</nav>

Livewire adds a data-current attribute to the link matching the current page, so active-link styling is a one-line Tailwind variant: class="data-current:font-bold".

Lazy loading keeps slow components off the critical path. A dashboard widget with a heavy query should not block the whole page. Render it with lazy and it loads when it scrolls into view; use defer and it loads immediately after the page renders. The @placeholder directive shows a skeleton while it loads, and #[Lazy] or #[Defer] attributes make the behaviour the component’s default:

<livewire:revenue lazy />

<!-- or defer it until right after page load -->
<livewire:revenue defer />

Islands are Livewire 4’s headline feature, and the most useful. Wrap an expensive region of a component in @island and only that region re-renders when it updates — the rest of the component is untouched. A dashboard with a revenue widget, a chart and a feed can refresh one number without re-running the other two queries:

<div>
    @island
        <div>
            Revenue: {{ $this->revenue }}
            <button type="button" wire:click="$refresh">Refresh</button>
        </div>
    @endisland

    <div>
        <!-- Other content, untouched by the refresh -->
    </div>
</div>

Islands can be lazy (@island(lazy: true) loads when visible, defer: true loads after page load), named so a button elsewhere can target them (wire:island="revenue"), and set to append or prepend content for infinite scroll and live feeds (wire:island.append="feed"). Two limits to remember: islands cannot be used inside @foreach or @if — put the loop inside the island instead — and they cannot see @php variables or loop variables from the parent template. Use component properties and computed properties inside islands, and they behave.

Laravel Livewire vs Inertia (and When to Pick Something Else)

The honest comparison, because the blog already covered Inertia in depth: Livewire and Inertia solve the same problem — a reactive UI without a separate API — from opposite sides. Livewire keeps you in PHP and Blade; Inertia keeps you in Vue or React with Laravel routing underneath.

Choose Livewire when your team thinks in PHP, the UI is mostly forms, tables, dashboards and admin panels, and you want one codebase with no build step. Choose Inertia when the interface needs genuine client-side state — a kanban board, a rich text editor, complex animations — or your team already writes Vue or React fluently. Many Laravel apps run both: Livewire for the admin area, Inertia for the customer-facing app.

And know when to pick neither. Livewire is a poor fit for true real-time features — chat, collaborative editing, live cursors — because every interaction is a server round-trip. For that, pair Livewire with Laravel Reverb, Laravel’s first-party WebSocket server, or reach for a dedicated JavaScript client. It is also the wrong tool for pages where most of the content is interactive and the server round-trip is felt on every keystroke; a search box with wire:model.live and no debounce is the classic example.

7 Mistakes That Make Livewire Feel Slow

Most “Livewire is slow” complaints trace back to one of these:

  1. Heavy queries in render(). Use #[Computed] properties, which are evaluated on demand and memoised for the request. A query in render() runs on every single update.
  2. wire:model.live without a debounce. Every keystroke is a request. Use .debounce.250ms on search fields and .blur where live feedback adds nothing.
  3. Forgetting resetPage(). Filter a paginated list without resetting the page and users land on an empty page.
  4. Fat public properties. Public properties are serialised and sent to the browser on every request. Keep them small — IDs and scalars, not entire collections or huge arrays.
  5. Missing wire:key in loops. Without keys, Livewire can update the wrong row when a list is filtered or reordered.
  6. Naming a method upload. It is reserved. Use save instead and save yourself a confusing error.
  7. Loading everything eagerly. A dashboard with five expensive widgets should lazy-load or defer the ones below the fold, and wrap the expensive regions in islands. The initial page load is the only performance number your users actually feel.

When to Use Livewire: The Short Version

Livewire is at its best exactly where most Laravel apps live: CRUD interfaces, admin panels, dashboards, search and filter UIs, and form-heavy workflows. It is not a replacement for a JavaScript framework when the interface itself is the product, and it is not a real-time system. But for the large middle of web applications — the part where a form, a table and a search box are 90% of the job — it removes an entire layer of architecture: no API, no client-side state management, no build step, no second language to keep in sync.

Livewire 4 makes that deal better. Single-file components cut the file-juggling that made Livewire 3 feel verbose, islands and lazy loading fix the performance complaints that used to push teams toward JavaScript, and wire:navigate makes the whole thing feel like an SPA. If you have been writing your interactive UIs in Vue or React because “Livewire is too slow” or “too many files”, the 2026 version is worth a second look. Install it, build the search component above, and judge it on a real feature — not on the version you last tried in 2023.

Further Reading & References

Related on HowToShipIt: Inertia.js Forms and Validation: The Complete Guide for Laravel + Vue 3 and Laravel Reverb: Real-Time Broadcasting Without Pusher’s Bill (2026).

Leave a Comment