Laravel storage symlink image view

Viewed 4193

I created a symlink to show images saved in the storage dir in my view.

For that I ran this command:

ln -s /Users/myname/code/myApp/storage/app /Users/myname/code/myApp/public/storage

That did create me a storage folder inside public, the storage folder contains a folder name images, which I want to show in my view.

I am trying to show them like this:

<img src="{{ asset('storage/app/' . $categoryValue->category_avatar) }}" />

But the image tag is still empty and I get this error message:

GET http://myapp.dev/storage/app/images/TpHsZhQBMVdihEtSwiPo6hz36l1hE2K5joFfaerB.jpeg 404 (Not Found

The path is correct but it still does not show the images.

3 Answers

Try a route:

    Route::get('storage/{folder}/{filename}', function ($folder,$filename)
{
    $path = public_path('storage/' .$folder.'/'. $filename);
    if (!File::exists($path)) {
        abort(404);
    }
    $file = File::get($path);
    $type = File::mimeType($path);
    $response = Response::make($file, 200);
    $response->header("Content-Type", $type);
    return $response;
});
Related