In this episode, we're diving right into handling file uploads and validation for our CSV importer. We start by hooking up the file input in our Livewire component to a property so we can accept file uploads. After a quick test, we run into an error because we didn’t include the WithFileUploads
trait—don’t worry, we fix that and get our files to upload to a temporary Livewire directory.
Next, we set up methods to listen for file updates and immediately validate what’s been uploaded. We look at how Livewire handles default validation on files (like max file size, required, etc.), and we talk through how you can set these rules either globally in the config or specifically in your component for CSV files.
We add validation rules to make sure we only accept CSV files of a certain size. To make the UI helpful, we wire up error messages so users get instant feedback if they try to upload the wrong file type or a file that’s too big.
By the end of this episode, you'll have a file upload input that lets you pick a CSV, validates it properly, and shows any relevant error messages. You’ll also see the groundwork laid for handling the file contents next—so we can start reading and processing these CSVs soon!