In this episode, we're focusing on how to display a list of uploaded files in your app, and—most importantly—keep that list up to date whenever someone uploads a new file. We'll start by creating a new Livewire component (called FileIndex
for simplicity), hook it up to the dashboard, and make sure it gets all the current user's files ordered by the latest upload.
You'll see how we loop through each file, show its name and location, and deal with the case where there are no files yet. We use some basic Blade features like @forelse
to handle this smoothly and make sure each file is keyed properly so Livewire can keep track.
Once the display is sorted, we go over how to auto-refresh the list whenever a file is uploaded. The main trick here is to use Livewire events: after a successful upload, we dispatch a custom refresh
event targeting the file list component. The component listens for this event and calls Livewire's built-in refresh
method, which reloads the data and updates the UI instantly.
The result is a handy, real-time file list that updates without any page reloads. Plus, you get some ideas for customizing further—maybe to flash messages, or perform other actions instead of or in addition to just refreshing the file list.