How to get selected records in PDF using filament 3
if there are 100 records from that few selected records pdf i need how to make that possible in filament 3
Solution
try this:
with this you dont have to use controller
Tables\Actions\BulkAction::make('generatePdf')
->label('Generate PDF')
->action(function ($records) {
$pdf = Pdf::loadView('pdf.selected-items', ['records' => $records]);
return response()->streamDownload(function () use ($pdf) {
echo $pdf->output();
}, 'selected-items.pdf');
})
->deselectRecordsAfterCompletion(),Tables\Actions\BulkAction::make('generatePdf')
->label('Generate PDF')
->action(function ($records) {
$pdf = Pdf::loadView('pdf.selected-items', ['records' => $records]);
return response()->streamDownload(function () use ($pdf) {
echo $pdf->output();
}, 'selected-items.pdf');
})
->deselectRecordsAfterCompletion(),<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selected Items</title>
<style>
/* Add any necessary styles here */
</style>
</head>
<body>
<h1>Selected Items</h1>
@foreach ($records as $record)
<h2>Item {{ $loop->iteration }}</h2>
<p>ID: {{ $record->id }}</p>
<p>Name: {{ $record->name }}</p>
@endforeach
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Selected Items</title>
<style>
/* Add any necessary styles here */
</style>
</head>
<body>
<h1>Selected Items</h1>
@foreach ($records as $record)
<h2>Item {{ $loop->iteration }}</h2>
<p>ID: {{ $record->id }}</p>
<p>Name: {{ $record->name }}</p>
@endforeach
</body>
</html>with this you dont have to use controller