I created an API with Laravel. I use Vuejs for the front end.
I would like to generate a PDF based on the user and download it with view. Only, it does not work.
Here is my controller:
public function generate($id)
{
$data = CoverLetter::where([
['id', '=', $id],
['user_id', '=', auth()->user()->id]
])->first();
$path = public_path() . '/pdf/' . $data->filename . '.pdf';
$pdf = PDF::loadView('pdf.coverletter', $data);
$pdf->save($path);
return response()->download($path);
}
And my function in vue :
async downloadCoverLetter(file) {
axios.get('/cover-letter/generate/' + file.id)
}
And my button for download :
<button @click="downloadCoverLetter(file)"></button>
But it doesn't download at all. How to do ? Thank you !