how to upload a file in livewire code example
Example 1: livewire file upload
use Livewire\WithFileUploads;
class UploadPhoto extends Component
{
use WithFileUploads;
public $photo;
public function save()
{
$this->validate([
'photo' => 'image|max:1024',
]);
$this->photo->store('photos');
}
}
Example 2: livewire file upload
<form wire:submit.prevent="save">
<input type="file" wire:model="photo">
@error('photo') <span class="error">{{ $message }}</span> @enderror
<button type="submit">Save Photo</button>
</form>