How to get file URL using Storage facade in laravel 5?

I've been experimenting using the new Flysystem integration with Laravel 5. I am storing 'localised' paths to the DB, and getting the Storage facade to complete the path. For example I store screenshots/1.jpg and using

Storage::disk('local')->get('screenshots/1.jpg')

or

Storage::disk('s3')->get('screenshots/1.jpg') 

I can retrieve the same file on different disks.

get retrieves the file contents, but I am hoping to use it in my views like this:

<img src="{{ Storage::path('screenshots/1.jpg') }}" />

but path, or anything able to retrieve the full path is not available (as far as I can see). So how can I return the full path? Or, I'm wondering if this is by design? If so, why am I not supposed to be able to get the full path? Or, am I going about this completely the wrong way?


Solution 1:

The Path to your Storage disk would be :

$storagePath  = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix()

I don't know any shorter solutions to that...

You could share the $storagePath to your Views and then just call

$storagePath."/myImg.jpg";

Solution 2:

This method exists since Laravel 5.4, you can get it by:

$path = Storage::disk('public')->path($filename);