简体   繁体   中英

how to display images from public folder in laravel 5.8?

i am trying to display an image which is located in storage/app/uploads . I already run the " php artisan storage:link " command and it was a success but its still not showing. When i also inspect the code in the browser the image is there together with the path. 'Upload' is linked to the image path.

    @foreach($user->posts as $post)
    <div class="col-4">
        <img class="w-100" src="/storage/{{ $post->image }}">
    </div>
    @endforeach

Try this solution:

use asset(), its get files from public folder

@foreach($user->posts as $post)
    <div class="col-4">
        <img class="w-100" src="{{ asset('images/' . $post->image) }}">
    </div>
@endforeach

you have 2 options either use the direct url or asset method--

@foreach($user->posts as $post)
    <div class="col-4">
        <img class="w-100" src="{{ asset(yourpath) }}">
    </div>
    @endforeach

OR

@foreach($user->posts as $post)
    <div class="col-4">
        <img class="w-100" src="{{ url(yourpath) }}">
    </div>
    @endforeach

your path would be after the storage directory in public directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM