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


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:

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

This will generate the full URL to the image, for example

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

$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.