如果产品在显示它的图像表中有多个图像,并且如果不存在

问题描述 投票:0回答:1

如果产品在显示它的图像表中有多个图像,并且如果不存在,则显示为空,我该如何做条件

@foreach($products as $product)
<tr>
    <td>{{ $product->id }}</td>
    <td>{{ $product->name }}</td>
    <td class="text-center">
        <span class="badge rounded-pill text-bg-primary">
            {{ App\Models\Project\Ecommerce\ProductImage::where('product_id', $product->id)->count() }}
        </span>
    </td>
    <td>


        // mutli image Product //
        @if (!empty($product->images))
            <img src="{{ asset('Image/ProductImage/'. $product->images->pull('0')->image) }}" alt="{{ $product->title_image }}" class="object-fit-contain" width="50" height="50">
        @endif
        // end mutli image Product //


    </td>
</tr>
@endforeach

尝试读取 null 上的属性“image”

php laravel image laravel-blade
1个回答
0
投票

使用嵌套foreach

 @if (!empty($product->images))

@endforeach($产品->图像作为$图像 图片) }}" alt="{{ $product->title_image }}" class="object-fit-contain" width="50" height="50"> @endforeach @endif

© www.soinside.com 2019 - 2024. All rights reserved.