How to get file URL using Storage facade in laravel 5?
To get the URL of a file using the Storage facade in Laravel 5, you can use the url
method. This method generates a URL for the file based on your Laravel configuration.
Here's an example:
<?php
use Illuminate\Support\Facades\Storage;
$url = Storage::url('file.txt');
This will return the URL of the file.txt
file.
Keep in mind that this method will only work if you have the filesystems.php
configuration file properly set up and the correct disks are specified.
If you want to get the URL of a file that is stored on a cloud storage service (such as Amazon S3 or Google Cloud Storage), you will need to set up a connection to that service in your filesystems.php
configuration file and use the correct disk name when calling the url
method.
For example:
<?php
$url = Storage::disk('s3')->url('file.txt');
This will return the URL of the file.txt
file that is stored on the S3 disk.