In this episode, we jump right into the simplest and quickest way to add modals to your Livewire applications by using the wire-elements/modal package. I'll walk you through the whole process from scratch—no prior setup needed beyond having Livewire and Tailwind CSS.
First up, we go over installation and setup, including where to place the modal directive in your layout. Then, we create a basic Livewire modal component, but there's a tiny twist: these modals should extend a base class provided by the package (not just be a normal Livewire component).
We then see how to launch modals both from inside other Livewire components (with wire:click
and event dispatching) and even from outside the world of Livewire, whether with Alpine.js or straight JavaScript. Super handy if you've got a dashboard or just a plain Blade file!
The next part focuses on passing data to your modals. Need to send a primitive value like a name? No problem. More interestingly, we look at passing Eloquent models (like User
). This package makes it easy to just pass an ID and have your modal resolve it to a model automatically—big timesaver.
After that, closing a modal gets covered—both by clicking outside the modal and with your own close button, or even programmatically from inside your component's methods (like after a save action).
Finally, if Tailwind isn’t your thing or you want to tweak the design, we quickly see how to publish and customize the modal’s view files as much as you want.
By the end, you’ll see just how quick and flexible modals can be in Livewire using this package, and you’ll be ready to start using (and customizing) them in your own projects!