Laravel Public url for storage files

Daniel Euchar picture Daniel Euchar · May 4, 2017 · Viewed 70.4k times · Source

I want to retrieve public url for all the files stored using

storage::putFile('public/spares');

So, this is the issue I'm using

storage::files('public/spares');

but it provides this output from laravel storage directory

public/spares/image1.jpg
public/spares/image2.jpg
public/spares/image3.jpg

how can I get the public link for the above

http://localhost/laravel/public/storage/spares/image1.jpg
http://localhost/laravel/public/storage/spares/image2.jpg
http://localhost/laravel/public/storage/spares/image3.jpg

**Edit **

Sending last modified data of files to view

$docs = File::files('storage/document');
$lastmodified = [];
foreach ($docs as $key => $value) {
   $docs[$key] = asset($value);
   $lastmodified[$key] = File::lastmodified($value);
}
return view('stock.document',compact('docs','lastmodified'));

Is this correct

Answer

Eric Tucker picture Eric Tucker · May 4, 2017

First you have to create the symbolic link from your public/storage directory to your storage/app/public directory so you can access the files. You can do that with:

php artisan storage:link

So then you can store your documents with:

Storage::putFile('spares', $file);

And access them as an asset with:

asset('storage/spares/filename.ext');

Check out the documentation on the public disk