I am using laravel 10, and have images inside /public/images , when i try yo use asset or public_path(), i get a duplicate prepended to the url like so
Using public_path();
file_get_contents(/var/www/soccia/var/www/soccia/public): Failed to open stream: No such file or directory.
Using asset();
file_get_contents(/var/www/socciahttp://158.68.112.29/images/1705750845_profile.png): Failed to open stream: No such file or directory
database contains paths like this (/images/img.png)
i did change asset_url in app.php
‘asset_url’ => env(‘ASSET_URL’, null),
but doesn’t fix the problem.
2
Answers
Can you try
public_path('images');
instead ofpublic_path();
?You can try
url($filepath)
For example, if a register to a filepath on your database is
images/1705750845_profile.png
and you need the path to this image in your public folder, you can useurl('images/1705750845_profile.png')
. The result will be (on a local development env):