I want to add a link in an email to get a pdf created "on the fly" by my app (Laravel 10 + Inertia + vue3).
The route for this request is in the AUTH part, therefore after a click in the email the user is first redirect to the login form. After a successfull identification Laravel forward to the previous request but at this moment the PDF content is raw printed in a modal instead of showing the pdf in a browser tab.
On the other hand if the user has already an opened session before the click (no need login form), the pdf download works like a charm.
I think it is because of the content-type not set correctly when laravel forward the previous request after correct login but I have no idea how to correct this. Would you have any ?
I use barryvdh/laravel-dompdf lib and here is the code of the pdf creation in the controler :
/**
* Get catalogue PDF
*/
public function download(Vente $vente)
{
$pdf = app('dompdf.wrapper');
$pdf->loadView('ventes/catalogue', [
'vente' => $vente->load('vehicules.pays'),
'title' => 'Catalogue' . $vente->libelle
])->setPaper('A4', 'landscape');
return $pdf->stream('catalogue-vente-' . $vente->libelle . '.pdf');
}
Posting here in case someone like me has the same problem.
The way I solved it is to do another redirect in my controller code, for example:
use Illuminate\Http\Request;
use Inertia\Inertia;
public function download(Request $request)
{
if ($request->header(Header::INERTIA)) {
return Inertia::location(url()->current());
}
//...
return $pdf->stream('download.pdf');
}