2
I have a system to download PDF files, which is happening and I try to download, and it just doesn’t download. I’ve seen in the by the inspector of the Chromo and there is no mistake.
Controller
class DownloadController extends Controller{
public function getDownload (){
$filename = 'certificacoes/teste.pdf';
$path = storage_path($filename);
return Response::make(file_get_contents($path), 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline; filename="'.$filename.'"'
]);
}
}
Jquery
$(function(){
$("body").on('click', '#download_link', function(e) {
e.preventDefault();
var creditos = {{$creditos}}
if(creditos == 0){
sweetAlert("Erro...", 'Não tem créditos disponiveis. Efectue upload de uma certificação', "error");
}else{
$.ajax({
type: 'POST',
url: '/download',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
//data: formData
}).done(function(response) {
}).fail(function(data) {
sweetAlert("Erro...", 'Ocorreu um erro ao efectuar o download. Por favor tente novamente!', "error");
});
}
});
});

Have you tried accessing URL straight through Ajax ?
– NoobSaibot
Some suggestions and cases that can cause this... 1. Check the permissions of folders and files. 2. Routes are correct, calling the function of the
Controllerand sending the answer? Make a console.log onajaxand returns a simple answer to see if everything is right in this process. 3. YourResponseis being added at the beginning of the file? 4. Have you tried using a library to do this in a simpler way? Index o [DOMPDF][1] [1]: https://github.com/barryvdh/laravel-dompdf– Darlei Fernando Zillmer