These are different ways I have tried in my controller to get image as response.
My images resides in public folder/img
.
switch ($document->ext) {
case 'doc':
$img = File::get(url('/img/doc.png'));
break;
case 'docx':
$img = File::get(asset('/img/docx.jpg'));
break;
case 'pdf':
$img = File::get(public_path('/img/pdf.png'));
break;
case 'ppt':
$img = File::get(url(public_path('/img/ppt.png')));
break;
default:
}
return new Response($img, 200);
I guess it is a better way in case we change the public_path
case 'doc':
return response()->file(public_path('img/doc.png'));
exit;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments