Reputation: 335
I have images in storage/app/uploads/image.jpg, I run command
Php artisan storage:link
After that in my view file I used this:
img src={{ asset('storage/app/upload/image.jpg') }}
but the image is not showing. I don't want to put my images in public folder. Any help would be highly appreciable.
Upvotes: 2
Views: 2559
Reputation: 1399
uploads
folder but then your src says upload/
.You need to create a route where you can fetch the images.
Route::get('images/{filename}', function ($filename)
{
$path = app_path('upload') . '/' . $filename;
$file = File::get($path);
$type = File::mimeType($path);
$response = Response::make($file, 200);
$response->header("Content-Type", $type);
return $response;
})->name('route.name');
Then in your blade file, all you have to do is call the route and the file name of the image separated by a comma.
img src={{ route('route.name', 'image.jpg') }}
Upvotes: 1
Reputation: 12847
If you don't want to store your files inside storage/app/public
(which is what the storage:link
symlink does), then you need to create a route:
Route::get('show-image', function() {
$file = storage_path('app/upload/image.jpg');
return response()->file($file);
})
Upvotes: 3