Filament: Table BulkActions: Download PDF From Selected Rows

Free Snippet

You can add a custom BulkAction to the table, building a file from the selected table rows and download it immediately.


How it works

This example is to build/download the PDF from the selected rows, but you can use it to build and download any file using the same Collection and response()->streamDownload().

Install the package for PDF:

composer require barryvdh/laravel-dompdf

Use this package to form the PDF from Blade.


use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Blade;
public static function table(Table $table): Table
return $table
// ...
->action(function (Collection $records) {
return response()->streamDownload(function () use ($records) {
echo Pdf::loadHTML(
Blade::render('pdf', ['records' => $records])
}, 'users.pdf');

The Blade file itself.


<th>Created At</th>
@foreach($records as $record)
<td>{{ $record->name }}</td>
<td>{{ $record->email }}</td>
<td>{{ $record->created_at }}</td>

A few of our Premium Examples: