How to show old form value when validation fails?

The old function retrieves an old input value flashed into the session:

$value = old('value');

How is this supposed to work in livewire? Say I have following method:

public function save(): void

If I examine the session in the debugbar, there are no form values being flashed when validation fails.

Hey, @artworkad

If you are talking about livewire use data binding and let it do the job for you.


<input type="text" wire:model="name"/>
'name' => 'required',

I know about data binding. However when e.g. name is required and you submit it as empty, the validation fails but the input field is still empty. Livewire does not populate the model with the old value.

Can you provide an example code from your blade file?

You misunderstand the use of old(). It restores the previous submission, not what you had before you submitted the form.

In the case of Livewire, old() has no purpose since the value is bound from frontend to backend. If you want to revert to the value before the user changed it then you need to keep a copy of the original value or refetch it from its source.

1 Like

Livewire is so freaking cool :wink:

<div x-data="{ name: '{{$name}}' }">


Why are you not using the livewire way of validation? You don’t need to make a traditional post request.
Just read the docs: