Introducing Laravel Quizzes! Play now

Laravel Livewire Tables Documentation

This is the documentation for v2. You can switch versions in the menu at the top. Check your current version with the following command:

composer show rappasoft/laravel-livewire-tables

Bulk Action Export

Here's an example on exporting your data from a bulk action using Laravel Excel:

use App\Exports\UsersExport;
use Maatwebsite\Excel\Facades\Excel;

public function bulkActions(): array
{
    return [
        'export' => 'Export',
    ];
}

public function export()
{
    $users = $this->getSelected();

    $this->clearSelected();

    return Excel::download(new UsersExport($users), 'users.xlsx');
}

The UsersExport class is a simple example of how to export data from a bulk action:

<?php

namespace App\Exports;

use 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::whereIn('id', $this->users)->get();
    }
}