我不知道为什么我会在我的刀片模板中得到这个错误,尽管一切似乎都很好。
Undefined array key 0 (View: ... 刀片模板代码如下:
@foreach($offers as $offer)
<div class="col-xl-2 col-lg-3 col-md-4 col-sm-2 mb-4">
<div class="card car-card">
<div
class="card-header p-0 mx-3 mt-3 position-relative z-index-1">
@if($offer["images"] !== null)
{{-- {{dd($offer)}}--}}
<img
src="{{$offer["images"][0]["url"]}}" <<-- THE ERROR IS HERE !!
alt="car image"
class="w-100 position-relative z-index-2 pt-2 car-front-image"/>
@else
<img v-else
class="w-100 position-relative z-index-2 pt-2 car-front-image"
src="/api/image/default/car/"
alt="car image">
@endif
</div> ... the rest of the code要约产出如下:

发布于 2022-01-29 10:41:29
正如@ As 55在评论中所指出的,可能存在空的images数组。因为@if($offer["images"] !== null)失败的原因是,即使您的数组是[],也不会是null
$array = [];
if($array){
dd('not empty');
}else{
dd('empty');
}所以通过这样做
@if($offer["images"])
{{-- {{dd($offer)}}--}}
<img
src="{{$offer["images"][0]["url"]}}" <<-- THE ERROR IS HERE !!
alt="car image"
class="w-100 position-relative z-index-2 pt-2 car-front-image"/>
@else
<img v-else
class="w-100 position-relative z-index-2 pt-2 car-front-image"
src="/api/image/default/car/"
alt="car image">
@endifhttps://stackoverflow.com/questions/70903729
复制相似问题