Lifecycle
Hook into different stages of a component's lifecycle.
Lifecycle Flow
Initial Request
boot()
→
mount()
→
render
Subsequent Requests
boot()
→
hydrate()
→
action
→
dehydrate()
→
render
Lifecycle Hooks
boot()
Called on every request, before anything else. Use for setup that should happen on every request.
public function boot()
{
// Runs on every request
}
mount(...$params)
Called only on initial render. Perfect for initialization logic.
public function mount(int $userId)
{
$this->user = User::find($userId);
}
hydrate()
Called on subsequent requests after state is restored.
public function hydrate()
{
// State has been restored from snapshot
}
dehydrate()
Called before state is serialized for the response.
public function dehydrate()
{
// Cleanup before snapshot
}
Property-Specific Hooks
React to changes on specific properties.
// Called before 'search' is updated
public function updatingSearch($value)
{
// $value is the new value
}
// Called after 'search' is updated
public function updatedSearch($value)
{
$this->results = $this->performSearch($value);
}
// For array properties, also receives the key
public function updatedItems($value, $key)
{
// $key is the array index that changed
}
Render Hooks
// Called before rendering
public function rendering($view, $data)
{
// Modify view or data before render
}
// Called after rendering
public function rendered($view, $html)
{
// Access the rendered HTML
}