How to get image url in laravel?

by giovanny.lueilwitz , in category: PHP Frameworks , 25 days ago

How to get image url in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by herminia_bruen , 24 days ago

@giovanny.lueilwitz 

To get the image URL in Laravel, you can use the asset() helper function.


Assuming you have an image stored in the public/images directory, you can generate the URL for the image like this:

1
$imageUrl = asset('images/image.jpg');


This will generate the full URL to the image, for example http://yourdomain.com/images/image.jpg.


Alternatively, if you are storing images in a different directory or a storage disk, you can use the Storage facade to get the URL:

1
$imageUrl = Storage::url('images/image.jpg');


This will generate the URL based on the disk configuration in your filesystems.php file.


You can then use the $imageUrl variable in your views to display the image.