Reputation: 53
So I'm building an app in Laravel and it's my first time using the framework by myself without any help aside from the internet, so I'm having quite a bit of trouble in some areas. One of them is that the images I upload seem to be impossible for laravel to find and serve, even though they are getting uploaded to the correct location in the filesystem. I am working on my local environment with Valet. Also, I have already made the symlink between storage and public as instructed by the documentation.
Here's the code that uploads the image:
$fileDir = 'public/enterprise/main';
$tempImage = request()->file('main_img');
$newImage = $tempImage->store($fileDir);
And here's how I'm trying to call it:
<div class="col-xs-8"><img src="{{ asset('storage/app/'.$enterprise->main_img) }}"></div>
The url laravel seems to be trying to reach is this:
http://vbi.dev/storage/app/public/enterprise/main/MgfjPKWL8DIFgHDrMccOCsOkZZH0QmFAsput07n5.jpeg
Finally, my config/filesystems file:
<?php
return [
'default' => env('FILESYSTEM_DRIVER', 'local'),
'cloud' => env('FILESYSTEM_CLOUD', 's3'),
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
'img' => [
'driver' => 'local',
'root' => storage_path('images')
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
];
Thank you for your attention.
Upvotes: 2
Views: 1688
Reputation: 11093
You should pass only the folders where to store the file in the public directory without including the public
, And you can specify a Disk inthe second argument like this :
$fileDir = 'enterprise/main';
$tempImage = request()->file('main_img');
$newImage = $tempImage->store($fileDir, 'public');
And the same thing in the view the asset method will automaticly add the path for the public folder for you :
<div class="col-xs-8"><img src="{{ asset($enterprise->main_img) }}"></div>
Upvotes: 1