Skip to main content

What is Livewire?

Building a dynamic UI in Laravel used to mean combining a JavaScript framework like Vue.js or React, or writing AJAX requests yourself. Livewire is a Laravel package that solves this problem. It lets you build reactive UIs using PHP and Blade only. Features that traditionally required JavaScript—real-time form validation, live search, counters, etc.—can all be implemented in PHP.
Livewire 4 works on Laravel 10 or later and PHP 8.1 or later. The current latest version is Livewire 4.

How it works

A Livewire component is a combination of a PHP class on the server and a Blade template. When a user clicks a button or types into a form, Livewire sends an AJAX request in the background, executes PHP, and applies only the changed portions to the page. You can write everything in PHP without worrying about this mechanism.

Installation

Run the following command in the root of your Laravel application.
Laravel’s package auto-discovery is enabled, so no additional configuration is required.

Creating a layout file

If you use it as a full-page component, a layout file is needed. You can generate one with this Artisan command:
This generates resources/views/layouts/app.blade.php:
@livewireStyles and @livewireScripts automatically load the Livewire and Alpine.js assets.

Your first component

An Artisan command is provided to generate Livewire components. Let’s build a simple counter.
This command creates a single-file component at resources/views/components/⚡counter.blade.php.
The ⚡ in the filename makes Livewire components identifiable at a glance. It improves editor visibility. You can disable it in the configuration if you prefer.
Edit the generated file as follows.
Embed this component in a Blade template using the ordinary Blade component syntax.
Every button click updates the count without a page reload. wire:click calls a PHP method instead of running JavaScript.

Properties and actions

Properties — wire:model

The wire:model directive two-way binds an input element to a component property.
By default wire:model only syncs with the server when an action (like a form submit) fires. If you want to sync on each keystroke, add the .live modifier.

Actions — wire:click and wire:submit

wire:click binds click events to methods, and wire:submit binds form submission events.

Real-time validation

In Livewire 4, the #[Validate] attribute lets you define validation rules directly on properties.
Properties annotated with #[Validate] run automatic validation on every update. Combined with wire:model.live.blur, you get a real-time validation experience where the error message appears the moment focus leaves the field.
$this->validate() validates all properties together on form submission. The recommended pattern is to combine automatic validation via #[Validate] with an explicit final validation.

Lifecycle hooks

Livewire components have several lifecycle hooks.

mount() — initialization

Use mount() to initialize a component. It replaces the constructor.

updated() — after property changes

If you want to run logic after a property updates, use updated(). To target a specific property, include it in the method name.
Every keystroke is automatically converted to lowercase.

Laravel integration

Working with Eloquent models

Livewire can hold Eloquent models directly as properties.

Form objects

Extracting complex forms into form objects keeps components simple.
Use the form object from a component.

Summary

Here’s where Livewire is especially well-suited: If you’ve used Blade before, you can start writing Livewire today. Its biggest strength is delivering interactive UIs without the learning curve of a JavaScript framework. For SPA-level advanced interactions, Inertia.js is the better fit, but for forms, admin panels, and data tables, Livewire is often simpler to build. Try starting with one small component.

Livewire official docs

See the official documentation for Livewire’s full feature set (file uploads, pagination, testing, and more).
Last modified on July 13, 2026