【问题标题】:Images I upload in Laravel don't show after I have tried many answers online. All the images I upload store alright but they don't display在网上尝试了很多答案后,我在 Laravel 中上传的图像不显示。我上传的所有图片都可以存储,但它们不显示
【发布时间】:2021-11-20 12:00:18
【问题描述】:

我有这个想法。可以上传,但是不显示。还有什么要补充的吗?

 <div class="col-md-4">
 <img class="img img-fluid img-thumbnail" src="/storage/profile_images/{{$profile->profile_image}}"/> </div>

这是我的show.blade.php 文件

<div class="col-md-4">
<img class="img img-fluid img-thumbnail" src="/storage/profile_images/{{$profile->profile_image}}"/></div>

这是player.blade.php 文件:

@if(count($players) > 0)
    <?php $index = 0; ?>
    @foreach($players as $player)
        <div class="col-md-4">
            <div class="card mb-1" style="width:300px">
                <div class="card-body">
                    <img class="img img-fluid img-thumbnail" style="height: 170px; width: 350px" src="/storage/profile_images/{{$player->profile_image}}">
                </div>
                <div class="card-footer">
                    <div class="row justify-content-center">
                        <a href="/playerprofiles/{{$player->id}}" class="h5">{{$names[$index]}}</a><br>
                    </div>
                    <div class="row">
                        <div class="col-10">
                            <span class="h6">Team: {{$player->current_fc}}</span><br>
                            <span class="h6">Position: {{$player->position}}</span><br>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php $index++; ?>
    @endforeach
    <div class="col-12 mt-3">
        {{$players->appends(request()->input())->links()}}
    </div>
@else
    <p>No Players available</p>
@endif
                    

【问题讨论】:

  • 您是否已将存储链接到公用文件夹? php artisan storage:link?
  • 是的,它告诉我公用文件夹已经存在
  • img 元素的 src attr 中的 url 是什么? (在元素检查器中)尝试在浏览器中打开图像

标签: php html laravel image


【解决方案1】:

您可以使用asset 函数,如下例所示:

 @php
    $imgUrl = '/storage/profile_images/'.$profile->profile_image;
 @endphp
<img class="img img-fluid img-thumbnail" src="{{ asset($imgUrl)}}"/>

还要确保使用以下命令链接存储:

php artisan storage:link

【讨论】:

    【解决方案2】:

    按照上述操作,您的图片问题将得到解决:

    第 1 步:

    从公共中删除存储文件夹

    第 2 步:

    在你的项目中运行这个命令

    player.blade.php

    php artisan storage:link
    

    第 3 步:

    按此替换或更改:

    show.blade.php

    <div class="col-md-4">
    <img class="img img-fluid img-thumbnail" src="{{ url('storage/profile_images/.$profile->profile_image) }}" /></div>
    

    第 4 步:

    根据您的需要更换或更改:

    @if(count($players) > 0)
        <?php $index = 0; ?>
        @foreach($players as $player)
            <div class="col-md-4">
                <div class="card mb-1" style="width:300px">
                    <div class="card-body">
                        <img class="img img-fluid img-thumbnail" style="height: 170px; width: 350px" src="{{ url('storage/profile_images/.$profile->profile_image) }}">
                    </div>
                    <div class="card-footer">
                        <div class="row justify-content-center">
                            <a href="/playerprofiles/{{$player->id}}" class="h5">{{$names[$index]}}</a><br>
                        </div>
                        <div class="row">
                            <div class="col-10">
                                <span class="h6">Team: {{$player->current_fc}}</span><br>
                                <span class="h6">Position: {{$player->position}}</span><br>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php $index++; ?>
        @endforeach
        <div class="col-12 mt-3">
            {{$players->appends(request()->input())->links()}}
        </div>
    @else
        <p>No Players available</p>
    @endif
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-14
      • 1970-01-01
      • 2021-02-21
      • 2017-02-07
      • 2014-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多