I´m trying to open PDF file
into modal with laravel 11
and vue js 3
.
To do this i´m building a function in my controller with this content:
public function getPdfPath(Request $request)
{
$params = $request->get('id');
dd(Storage::disk('contracts')->get('/1/contrato_1.pdf'));
return response(Storage::disk('contracts')->get('1/contrato_1.pdf'), 200)
->header('Content-Type', 'application/pdf');
}
this dd()
return null.
i have a new disk into filesystem:
'contracts' => [
'driver' => 'local',
'root' => storage_path('app/public/contracts'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
in my vue
i have:
$("#contract_preview").modal('show');
axios.get('/contracts/get-pdf-path', { params: { 'id': id } } )
.then((response) =>{
console.log(response);
document.getElementById("contract_document").setAttribute("src", response.data);
})
.catch(err => console.warn(err));
and my modal it´s:
<iframe id="contract_document" src="" width="790" height="500"></iframe>
but always return null or bad request… i don´t know tha i´m doing wrong.
Also i try with:
$pdfPath = storage_path('app/public/contracts/1/contracto_1.pdf');
return response()->download($pdfPath, 'sat_pdf.pdf', ['Content-Type' => 'application/pdf']);
with this code, in my console return:
%PDF-1.4
1 0 obj
<<
/Title (��
......
But not can view my pdf in my modal.
Anybody can help me, please?
PD: thanks for readme and sorry for my bad english