I have got user\'s avatars uploaded in Laravel storage. How can I access them and render them in a view?
The server is pointing all requests to /public
,
If you are like me and you somehow have full file paths (I did some glob() pattern matching on required photos so I do pretty much end up with full file paths), and your storage setup is well linked (i.e. such that your paths have the string storage/app/public/
), then you can use my little dirty hack below :p)
public static function hackoutFileFromStorageFolder($fullfilePath) {
if (strpos($fullfilePath, 'storage/app/public/')) {
$fileParts = explode('storage/app/public/', $fullfilePath);
if( count($fileParts) > 1){
return $fileParts[1];
}
}
return '';
}
According to Laravel 5.2 docs, your publicly accessible files should be put in directory
storage/app/public
To make them accessible from the web, you should create a symbolic link from public/storage
to storage/app/public
.
ln -s /path/to/laravel/storage/app/public /path/to/laravel/public/storage
Now you can create in your view an URL to the files using the asset helper:
echo asset('storage/file.txt');
If you are on windows you can run this command on cmd:
mklink /j /path/to/laravel/public/avatars /path/to/laravel/storage/avatars
from: http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html
without site name
{{Storage::url($photoLink)}}
if you want to add site name to it example to append on api JSON felids
public function getPhotoFullLinkAttribute()
{
return env('APP_URL', false).Storage::url($this->attributes['avatar']) ;
}
If disk 'local' is not working for you then try this :
'default' => env('FILESYSTEM_DRIVER', 'public'),
from project_folder/config/filesystem.php
php artisan config:clear
php artisan storage:link
To get url of uploaded image you can use this Storage::url('iamge_name.jpg');
You can run this command in your console to make link:
php artisan storage:link
Reference link