In this episode, we add drag and drop uploading to our import modal! Previously, you could only click to upload a file, but that's not super user-friendly—so we're leveling things up.
We start by making our upload area into an Alpine component (don't worry if Alpine is new to you; it's easy and already installed if you're using Breeze). We set up a dropping
state to track when a file is being dragged over the upload area and use that state to automatically change the border color, giving users nice visual feedback.
Next, we wire up the drag-and-drop events—using Alpine's x-on
for dragover
, dragleave
, and drop
. We prevent the default browser behavior, toggle our visual state, and finally, handle the drop
event. We do a quick check to make sure only one file is being dropped, then pass the file directly to Livewire for uploading (super simple with this.upload
).
We finish by tidying up—making sure our visual cues reset when the drag is done and thoroughly testing that both click-to-upload and drag-and-drop work just as expected. By the end of this lesson, the import modal supports a much nicer, more modern file upload workflow!