Skip to content
Livewire Laravel

What Is Livewire? How Laravel Livewire Works Under the Hood

Raheel Shan

Raheel Shan

July 6th, 2025 · 9 min read

What Is Livewire? How Laravel Livewire Works Under the Hood

Livewire is a Laravel framework for building interfaces in PHP. A component is a PHP class plus a Blade view. When users click or type, Livewire sends the state to the server, re-renders the view and patches the changed HTML.

That is the short answer to "what is Livewire". The rest of this post opens up a component and traces what happens from the first render to the network request that updates the page, then compares Livewire with Blade plus HTMX and with Inertia.

Quick answer

  1. A Livewire component is a PHP class with public properties and methods, plus a Blade view.
  2. The first request renders the view to normal HTML and embeds a snapshot of the component's state.
  3. wire: attributes such as wire:click and wire:model tell Livewire's JavaScript which events to watch.
  4. On an event, Livewire posts the snapshot and the requested actions to the server, which rebuilds the component and runs the method.
  5. The server returns fresh HTML and a new snapshot, and Livewire morphs the DOM to match.

What is a Livewire component?

Create one with Artisan:

php artisan make:livewire Counter

The class holds state and behaviour:

// app/Livewire/Counter.php
namespace App\Livewire;

use Livewire\Component;

class Counter extends Component
{
    public int $count = 0;

    public function increment()
    {
        $this->count++;
    }

    public function render()
    {
        return view('livewire.counter');
    }
}

The view draws it:

{{-- resources/views/livewire/counter.blade.php --}}
<div>
    <h1>{{ $count }}</h1>
    <button wire:click="increment">+</button>
</div>

Use it in any Blade page with <livewire:counter />. The public $count property is the component's state. A Livewire component must have a single root element, which is why everything sits inside one div.

How does Livewire work?

Four ideas make it work: the component class, the snapshot, the wire: attributes and one update request.

Components are PHP classes

Each component extends Livewire\Component. It can hold properties, lifecycle hooks and methods, query the database and return a Blade view. Logic, data and rendering stay on the server, in the language Laravel developers already use.

The first render is plain HTML

When a page loads, Livewire renders the component's Blade view on the server and puts the resulting HTML in the response. Search engines and users without JavaScript get real markup. Livewire's JavaScript is injected automatically in Livewire 3, so you do not add a script tag yourself.

The snapshot carries the state

Alongside the HTML, Livewire embeds a snapshot of the component. Between requests it serializes the PHP component into JSON that JavaScript can hold. A snapshot has three top-level keys: data (the public properties), memo (metadata such as the component id and name) and checksum. A simplified snapshot for the counter looks like this:

{
    "data": { "count": 0 },
    "memo": { "id": "Z1x...", "name": "counter" },
    "checksum": "a1b2c3..."
}

The checksum is a hash of the snapshot. If someone edits the snapshot in the browser, the checksum no longer matches and Livewire throws an error instead of trusting it. The checksum protects the snapshot as a whole, but public properties are still user input: validate and authorize them before you save anything, and use #[Locked] on properties the browser must never change.

Wire attributes drive interactivity

Livewire's JavaScript scans the DOM for attributes and attaches event handlers for you:

  • wire:click="increment" calls a component method on click.
  • wire:model="email" binds an input to a public property.
  • wire:submit="save" calls a method when a form is submitted.

You never write a handleClick() function. Livewire listens for the event and talks to the server.

Requests and DOM diffing

When you click the button, Livewire sends one request containing the snapshot, any property updates and the list of method calls. The server rebuilds the component from the snapshot, applies the updates, runs increment(), re-renders the view and returns the new HTML plus a new snapshot. Livewire then morphs the existing DOM to match the new HTML, so only the changed parts are touched and focus and scroll position survive.

In Livewire 3 every component update goes to one endpoint, POST /livewire/update, not a route per component. The old /livewire/message/{component} URL belongs to Livewire 2.

How does wire:model behave?

In Livewire 3, wire:model is deferred by default: typing does not send a request. The value is sent along with the next action, such as a wire:click or a form submit. To send updates as the user types, use wire:model.live, which adds a 150 millisecond debounce. Other modifiers include .live.debounce.250ms, .blur and .change. Livewire 2 sent a request on every input by default, so older tutorials describe the opposite.

Livewire vs Blade with HTMX vs Inertia

All three let you build interactive Laravel apps without hand-writing a JSON API. They differ in where state lives and what travels over the network.

  • Livewire: state lives in a PHP component, and the server sends back HTML after each action. Best when you want rich, stateful UI such as live validation, filters and modals, written only in PHP.
  • Blade with HTMX: no component state. Each interaction requests a Blade partial and swaps it in. Fewer moving parts and no server-side component lifecycle. See the Blade partial API pattern with HTMX.
  • Inertia: pages are React, Vue or Svelte components, and Laravel sends props as JSON. Best when you want a client-side framework and a SPA feel, at the cost of a JavaScript build and two languages.

A rough rule: pick Livewire for stateful UI in a PHP-only team, HTMX for server-rendered pages with a few dynamic parts, and Inertia when the front end is already React or Vue. To see the same live search built with Livewire and with HTMX, read HTMX vs Livewire.

When not to use Livewire

Every action is a network round trip, and the whole component state travels with it. That is fine for forms and dashboards, but it is a poor fit for interactions that must respond instantly, such as drag and drop or canvas drawing. Large public properties, like big arrays or collections, also make each request heavier. I argued for a lighter stack in Skip Livewire: why Blade, AQC and Alpine might be all you need, and in Livewire without Livewire I show how far plain Laravel goes.

FAQ

What is Livewire in Laravel? A Laravel package for building dynamic interfaces with PHP classes and Blade views. Components keep their state on the server and update the page through requests, so you write little or no JavaScript.

How does Livewire work? It renders a component to HTML with an embedded snapshot of its state. On a click or input, it posts the snapshot and the action to the server, which re-renders the component and returns HTML that Livewire morphs into the page.

What is a Livewire component? A PHP class extending Livewire\Component with public properties and methods, paired with a Blade view that has a single root element.

Livewire vs Blade: what is the difference? Blade renders HTML once per page load. Livewire adds a component layer on top of Blade so parts of the page can re-render after user actions without a reload.

Livewire vs Inertia? Livewire keeps you in PHP and Blade, with the server returning HTML. Inertia uses React, Vue or Svelte for the pages and Laravel returns JSON props.

Build the interactive parts without React

Live search, tables and forms on server-rendered HTML, with HTMX or jsRibbon and no build step.

Bring the page you want to make interactive and we build the first piece together in 60 minutes.

Book an HTMX and jsRibbon call

Found this useful?

Support the work that goes into these posts.

Support
Comments


Comment created and will be displayed once approved.