Lifecycle Hooks
Laravel Livewire Documentation Reference
Since Magewire is heavily inspired by Laravel Livewire, many concepts are either identical or very similar. To avoid duplicating documentation, this page only covers Magewire-specific and platform-specific details. For all general concepts and in-depth explanations, you can refer to the corresponding Laravel Livewire documentation.
mount() receives layout XML arguments
mount() receives magewire:mount:* layout arguments as named parameters:
public function mount(int $productId): void
{
$this->productId = $productId;
$this->name = $this->productRepository->getById($productId)->getName();
}
boot() for Magento guards
Run on every request, before hydration — use for authorisation and dependency resolution:
public function boot(): void
{
if (! $this->customerSession->isLoggedIn()) {
throw new \Magento\Framework\Exception\AuthorizationException(__('Login required.'));
}
}
Swap templates per state
Component has no render() method — the block's configured PHTML renders automatically. To switch templates based on state, use the rendering hook and set the block's template before render:
public function rendering(): void
{
$this->magewireBlock()->setTemplate(
$this->state === 'review'
? 'Vendor_Module::magewire/review.phtml'
: 'Vendor_Module::magewire/default.phtml'
);
}