In this lesson, we will use Laravel Excel package to export selected products into CSV, XLSX, and PDF.
Let's start by adding three buttons, which will trigger the export()
method in the Livewire component.
resources/views/livewire/products-list.blade.php:
<div class="mb-4"> <div class="mb-4"> <a class="inline-flex items-center px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase bg-gray-800 rounded-md border border-transparent hover:bg-gray-700"> Create Product </a> </div> <button type="button" wire:click="deleteConfirm('deleteSelected')" wire:loading.attr="disabled" @disabled(! $this->selectedCount) class="px-4 py-2 mr-5 text-xs text-red-500 uppercase bg-red-200 rounded-md border border-transparent hover:text-red-700 hover:bg-red-300 disabled:opacity-50 disabled:cursor-not-allowed"> Delete Selected </button> <x-primary-button wire:click="export('csv')">CSV</x-primary-button> <x-primary-button wire:click="export('xlsx')">XLSX</x-primary-button> <x-primary-button wire:click="export('pdf')">PDF</x-primary-button> </div>
Next, we need to install the Laravel Excel package and create Export...