Ben Borgers

How to customize validation messages in Livewire

November 15, 2020

Livewire allows you to write validation in a protected $rules property that is used whenever you call $this->validate() or $this->validateOnly('propertyName').

If you want to show a different error message for one of the validation rules, you can use the protected $messages property to do it.

For example, say I have this Livewire Blade view, with a simple input and the possibility of showing an error message for that input’s value:

  <input wire:model="text" />

    <p>{{ $message }}</p>

I could leverage the $messages property like this to override the default validation error for the text minimum length rule:


use Livewire\Component;

class LivewireComponent extends Component
    public $text = '';

    protected $rules = [
        'text' => 'required|min:3'

    protected $messages = [
        'text.min' => 'Keep typing...'

    public function updated($property)
        // Every time a property changes
        // (only `text` for now), validate it

    public function render()
        return view('livewire-component');

Subscribe to my newsletter!

A weekly round-up of new blog posts and updates to projects I’m working on.