-
composer.json
Open in GitHub{ // "require": { "php": "^7.3|^8.0", // "laravel/framework": "^8.65", "maatwebsite/excel": "^3.1", // }, // }
-
app/Exports/UsersExport.php
Open in GitHubuse App\Models\User; use Maatwebsite\Excel\Concerns\FromCollection; class UsersExport implements FromCollection { public $users = []; public function __construct($users) { $this->users = $users; } public function collection() { return User::query()->whereIn('id', $this->users)->get(); } }
-
app/Http/Livewire/Admin/User/Index.php
Open in GitHubuse App\Exports\UsersExport; use Livewire\Component; use Maatwebsite\Excel\Facades\Excel; class Index extends Component { // public function exportSelectedQuery() { return Excel::download(new UsersExport($this->selectedUsers), 'users-'.date('Y-m-d').'.xlsx'); } // }
-
resources/views/livewire/admin/user/index.blade.php
Open in GitHub// ... <div class="btn-group btn-group-sm w-100"> <button type="button" wire:click="deleteSelected" class="btn">{{ __('bap.delete') }} ({{ count($selectedUsers) }})</button> <button type="button" wire:click="exportSelectedQuery" class="btn">{{ __('bap.export') }} ({{ count($selectedUsers) }})</button> </div> // ...