Reputation: 127
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.
Upvotes: 3
Views: 5197
Reputation: 1840
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;
});
Upvotes: 1
Reputation: 2436
You specified incorrect directory as source file while creating symbolic link, you should change:
ln -s /Users/myname/code/myApp/storage/app /Users/myname/code/myApp/public/storage
to:
ln -s /Users/myname/code/myApp/storage/app/public /Users/myname/code/myApp/public/storage
Or you can use the storage:link
Artisan comand:
php artisan storage:link
And then, you can create a URL using the asset
helper:
<img src="{{ asset('storage/file.txt') }}" />
Upvotes: 0
Reputation: 1088
Seems like you've made the incorrect link. It should be
storage/app/public -> public/storage
(you've missed the public part). In order to avoid any errors with directories, you should use the special Artisan command:
php artisan storage:link
Upvotes: 6