Laravel 5.4 Storage link

2019-07-10 05:11发布

i would like to show a picture in html file i go to the link folder public/storage/image is empty but in the storage/image i find the file and its also saved in the data base.*

@foreach($cvs as $cv)
                    <div class="col-sm-6 col-md-4">
                    <div class="thumbnail">
                        <img src="{{ asset('storage/'.$cv->photo) }}" alt="...">
                        <div class="caption">
                        <h3>{{ $cv->titre }}</h3>
                        <p>{{$cv->presentation}}</p>
                        <p>
                            <a href="#" class="btn btn-primary" role="button">Afficher</a>
                            <a href="#" class="btn btn-success" role="button">Modifier</a>
                            <a href="#" class="btn btn-danger" role="button">Supprimer</a>
                         </p>
                        </div>
                    </div>
                    </div>
                    @endforeach
                    </div>
               </div>

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-10 05:38

The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. Laravel doc

Create Symbolic link in Linux

ln -s source_file myfile
查看更多
做个烂人
3楼-- · 2019-07-10 05:47

As Mayank Majithya notes, a symbolic link is one common way to access storage/app/public/ files from the public/ directory, and in fact the method the Laravel docs say you should use.

If you are on shared hosting that disallows this, you could also try to use Laravel's storage_path() helper function, like so: <img src="{{ storage_path('subpaths/under/storage/filename.jpg') }}"> (reference).

I also notice you mention the images are stored in the database. If you mean the whole file is stored, it may be more efficient (once you have the file path figured out) to store only the file path in your database, rather than the whole file (since it is already stored on disk). You can then use your model to get the path (assuming your table has columns for, say, 'src' and 'alt'):

<img src="{{ $mymodel->src }}" alt="{{ $mymodel->alt }}">
查看更多
疯言疯语
4楼-- · 2019-07-10 05:48

solved it with just a simple modification on the filesystems config/file systems from :

'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ]

to :

'local' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
        ]
查看更多
登录 后发表回答