Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Hooks: updated() and updatedField()

Premium
2 min read

Livewire has a variety of lifecycle hooks that allows you to execute code at a specific time. In this lesson, let's see the updated hook.


The updated hook can be called in two ways every time the property is updated. The first way is to have an updated method that accepts two parameters, $property and $value.

Let's update the post title into a headline. Every word will have a capital first letter. In the Livewire component, we add an updated method.

use Illuminate\Support\Str;
 
class CreatePost extends Component
{
public PostForm $form;
 
// ...
 
public function updated($property): void
{
if ($property == 'form.title') {
$this->form->title = Str::headline($this->form->title);
}
}
 
// ...
}

Because we added all of the post properties to the Form Object, we can check if the updated property is correct using the dot notation. If it is the form.title, we set the title to the headline using the Laravel helper.

Now after the title is written, the title gets changed.

updated lifecycle hook

But there is a second method where...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

JL
Joshua Lictan ✓ Link copied!

Why i cant add space ? it always delete the space

N
Nerijus ✓ Link copied!

Maybe your input has .live added? Hard to say without add least some parts of the code.

G
gpalmer711 ✓ Link copied!

If you are following the tutoral then the title input may contain the following

wire:keydown="validateTitle"

This causes the update hook to fire each time you press a key.

N
Nerijus ✓ Link copied!

Or wire:model.live

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.