Images stored in the public/storage
directory are not displaying on the live server (shared hosting environment), but they work perfectly on localhost.
Trainee.php
Method
public function getProfilePicture()
{
if ($this->picture && Storage::disk('public')->exists($this->picture) == 1) {
return Storage::disk('public')->url($this->picture);
}
return asset('/images/blank_profile_picture.png');
}
Blade Template
<img src="{{ $trainee->getProfilePicture() }}">
filesystems.php
Configuration
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app/private'),
'serve' => true,
'throw' => false,
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
'throw' => false,
],
],
Below are the commands I ran to set up the symbolic link for the storage directory:
php artisan storage:link
INFO The [public/storage] link has been connected to [storage/app/public].
chmod -R 755 storage
chmod -R 755 public/storage
After running the commands:
ls -l public
lrwxrwxrwx 1 user user 61 Dec 17 10:22 storage -> /home/customer/www/.../storage/app/public
...
contains the app path that I'm passing in .env as APP_URL
storage/app/public/trainee-profile-pictures
directory:ls -l storage/app/public/trainee-profile-pictures/
-rwxrwxr-x 1 user user 26990 Dec 17 07:36 gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg```
The getProfilePicture()
method in the Trainee.php
model should return the correct URL of the image, and the <img>
tag in the Blade template should display the image.
Actual image path:
/storage/app/public/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
Values observed during debugging:
$this->picture = trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
Storage::disk('public')->exists($this->picture) = 1
$trainee->getProfilePicture() = https://.../storage/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
storage_path('app/public/'.$this->picture) =
/home/customer/www/.../storage/app/public/trainee-profile-pictures/gAgoBddnYT7SH0eiV2u000bqZT5j2TGQjcoedHlj.jpg
Please guide me on:
Can you find the images yourself 'through' the symlink. E.g. does ls public/storage/
list the content of storage/app/public
? Then try ls public/storage/trainee-profile-pictures
etc. If not, then the sy
Something to try is make your own symlink instead of relying on artisan:
sudo ln -snf /home/customer/www/<path>/storage/app/public /home/customer/www/<path>/public/storage
If that all works, then I'd guess it's a problem with reading the files. Seems like you already checked permissions, so maybe try dumping the images into the actual public
folder directly, instead of using the symlink (just delete it), and see if the code finds the files then.
Is there any error message logged when failing to read the images?
Thanks for making your question so easy to read
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community