Home > Back-end >  Laravel asset() function
Laravel asset() function

Time:03-06

As far as I know, the asset function is used to make a link to the public directory.

But why with this code the image does not show for me

  <img src='{{asset("/images/".$user->picture)}}'

It works only if I use it like this

<img src='{{asset("/storage/images/".$user->picture)}}'

Can anyone clarify to me?

CodePudding user response:

It's likely that your application is using the php artisan storage:link command, which links these 2 directories together:

{project}/storage/app/public symlinked to {project}/public/storage.

It is a convenient way to manage storage, since if necessary you can move around that origin directory and only change the symlink again to make it work.

See https://laravel.com/docs/9.x/filesystem#the-public-disk . The configuration can be found under config/filesystems.php::links

CodePudding user response:

That's perfectly normal. Your assets should be in the public folder. If you look at the .htaccess file in there, you'll see this:

Handle Front Controller...

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

This ensures that files located under /public are served directly without involving Laravel while all other urls go through index.php.

In the simplest form, assets means JavaScript, CSS, and images which lie directly under the public directory and are publicly accessible using a URL.

  • Related