Laravel 5 - How to access image uploaded in storage within View?

前端 未结 12 2716
悲哀的现实
悲哀的现实 2020-11-22 14:05

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,

12条回答
  •  天命终不由人
    2020-11-22 14:12

    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 '';
        }
    

提交回复
热议问题