Lifecycle Hooks in Livewire v4
February 01, 2026
•
1 min read
•
28 views
Livewire v4 components have lifecycle hooks that run at specific times.
Complete Lifecycle Example
class UserProfile extends Component
{
public User $user;
public string $name;
public string $email;
// Runs once when component is first created
public function mount(User $user): void
{
$this->user = $user;
$this->name = $user->name;
$this->email = $user->email;
}
// Runs on every request (before hydration)
public function boot(): void
{
// Good for authorization checks
if (!auth()->user()->can('view', $this->user)) {
abort(403);
}
}
// Runs after component is hydrated from state
public function hydrate(): void
{
// Re-initialize non-persisted data
}
// Runs before a specific property updates
public function updatingName($value): void
{
$this->name = trim($value);
}
// Runs after a specific property updates
public function updatedName($value): void
{
$this->validate(['name' => 'required|min:2']);
}
// Runs before any property updates
public function updating($property, $value): void
{
logger("Updating {$property} to {$value}");
}
// Runs after any property updates
public function updated($property, $value): void
{
logger("{$property} updated to {$value}");
}
public function render(): View
{
return view('livewire.user-profile');
}
}
Related Posts
Introduction to Livewire v4: The Future of Laravel Full-Stack Development
Discover what's new in Livewire v4 and why it's a game-changer for Laravel developers.
Single-File Components in Livewire v4: The View-First Approach
Learn how to create single-file components with the new .wire.php extension.
Multi-File Components (MFC) in Livewire v4
Organize complex components with the new multi-file component structure.
Comments (0)
No comments yet. Be the first to comment!