How to access the public directory of Storage in Laravel 5.3?

4

I need to access saved images in the /storage/app/public directory on views , but I can not, I have a 404 .

I'm doing the following:

<div class="row">
    <img src="../storage/app/public/3.jpg">
</div>

But he does not find the image.

Is there any helper of Laravel that accesses this folder?

    
asked by anonymous 16.12.2016 / 13:03

1 answer

2

If storage/public refers to something like /home/user/projeto-em-laravel/public/storage/public I think it would be interesting to change your strategy, the storage folder should not be accessed directly and will not, unless you have done something very wrong, the correct is to use the asset function, like this:

echo asset('storage/file.txt');

According to the link documentation

The public disk is intended for files that will be publicly accessible. By default, the public disk uses the local disk and stores those files in storage/app/public .

To make them accessible from the web, you can create a symbolic link from public/storage to storage/app/public .

To create the symlink you should run the command:

php artisan storage:link

Once created, you can create a url and use the helper function called asset within a route:

echo asset('storage/file.txt');

You can access this way (I'm not sure if you have to type the prefix public/ ):

<img src="storage/3.jpg">

DocumentRoot "/home/user/projeto-em-laravel/public"
<Directory "/home/user/projeto-em-laravel/public">
    AllowOverride all
</Directory>

Then the images would be accessible like this:

<img src="3.jpg">

If it is in the root folder, it would look like this:

<img src="images/3.jpg">

If it is for /home/user/projeto-em-laravel/public/images/3.jpg to use in the background in a CSS like this images/3.jpg then you should use /home/user/projeto-em-laravel/public/css/meucss.css , like this:

seletor {
    background: url(../images/3.jpg);
}
  

Read more at: link   

    
16.12.2016 / 13:06