Stream PDF to response

Hi guys, can you help me stream PDF to response directly from action? Is it even possible? Should I save my PDF firstly?
Action::make('generateReport')
->form([
DatePicker::make('from')
->required(),

DatePicker::make('to')
->required(),
])
->action(fn (array $data) => app(GenerateReportAction::class)->execute($data['from'], $data['to']))
Action::make('generateReport')
->form([
DatePicker::make('from')
->required(),

DatePicker::make('to')
->required(),
])
->action(fn (array $data) => app(GenerateReportAction::class)->execute($data['from'], $data['to']))
class GenerateReportAction
{
public function execute(mixed $from, mixed $to)
{
return pdf()
->view('print.report')
->name('report.pdf');
}
}
class GenerateReportAction
{
public function execute(mixed $from, mixed $to)
{
return pdf()
->view('print.report')
->name('report.pdf');
}
}
I am using Spatie Laravel PDF: https://spatie.be/docs/laravel-pdf/v1/basic-usage/responding-with-pdfs
1 Reply
dissto
dissto8mo ago
public function execute(mixed $from, mixed $to)
{
return pdf()
->view('print.report')
->name('report.pdf')
->download(); // ??
}
public function execute(mixed $from, mixed $to)
{
return pdf()
->view('print.report')
->name('report.pdf')
->download(); // ??
}
From the spatie docs:
By default, the PDF will be inlined in the browser
This is not possible from within an action I believe unless you want to open a new tab, but then you can no longer use ->action 🤔
Want results from more Discord servers?
Add your server