jbowman99
2 years ago
148
0
Laravel

display PDF file from storage in new window

Posted 2 years ago by jbowman99

I have a page that lists pdf's stored in storage/app/flyers trying to make a link when clicked it will open up a new window and display the flyer. I get this error:

NotFoundHttpException in RouteCollection.php line 161:

heres my link:

<a href="/show/{{$flyer->file}}" target="_blank">
            <img class="flyer-thumbnail" src="/flyer_thumbs/{{$flyer->thumbnail}}">
        </a>

here's my route

Route::get('/show/{flyer}', function ($flyer) {
    $filename = $flyer->file;
    $path = storage_path($filename);

    return Response::make(file_get_contents($path), 200, [
        'Content-Type' => 'application/pdf',
        'Content-Disposition' => 'inline; filename="' . $filename . '"'
    ]);
});

not sure how to correct, assuming its a path issue, but i could be wrong

Please sign in or create an account to participate in this conversation.