我在讀取從控制器傳遞到刀片的以下“$photos”數組時遇到問題。 0 => array:2 [▼ "destinationPath" => "images/" "filename" => "15-1-tue-apr-7-2020-130-am-34824.jpg" ] 1 => array:1 [▼ 0 => array:2 [▼ "destinationPath" => "images/" "filename" => "15-1-tue-apr-7-2020-130-am-89914.jpg" ] ] 2 => array:1 [▼ 0 => array:2 [▼ "destinationPath" => "images/" "filename" => "15-1-tue-apr-7-2020-130-am-30958.jpg" ] ] 3 => array:1 [▼ 0 => array:2 [▼ "destinationPath" => "images/" "filename" => "15-1-tue-apr-7-2020-130-am-68870.jpg" ] ]]如果我直接在刀片中調用照片,如下所示,它可以拉出圖像: <img class="img-fluid options-item" src="{{$path}}/{{ $photos[0]['destinationPath'] }}{{ $photos[0]['filename'] }}" alt="">但是當我嘗試遍歷數組時@for ($i = 0; $i < count($photos); $i++) <img class="img-fluid options-item" src="{{$path}}/{{ $photos[$i]['destinationPath'] }}{{ $photos[$i]['filename'] }}" alt="">@endfor我收到以下錯誤:Facade\Ignition\Exceptions\ViewExceptionUndefined index: destinationPath (View: C:\Apache24\htdocs\collection\proof\resources\views\pages\gallery.blade.php)我還嘗試了以下結果是否定的:@foreach ($photos as $photo) <img class="img-fluid options-item" src="{{$path}}/{{ $photo['destinationPath'] }}{{ $photo['filename'] }}" alt="">@endforeach結果:Facade\Ignition\Exceptions\ViewExceptionUndefined index: destinationPath (View: C:\Apache24\htdocs\collection\proof\resources\views\pages\gallery.blade.php)任何關于正確語法的指導將不勝感激。
1 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
在這里,您首先使用的是@for,但最終使用的是@endforeach。你想用哪一個?for循環還是foreach循環?
@for ($i = 0; $i < count($photos); $i++)
<img class="img-fluid options-item" src="{{$path}}/{{ $photos[$i]['destinationPath'] }}{{ $photos[$i]['filename'] }}" alt="">
@endforeach
如果你想使用foreach
@foreach ($photos as $photo)
<img class="img-fluid options-item" src="{{$path}}/{{ $photo->destinationPath }}{{ $photo->filename }}" alt="">
@endforeach
您收到錯誤的原因是$photo['destinationPath']數組語法。$photo實際上是object。所以你需要使用->來訪問它的屬性。
- 1 回答
- 0 關注
- 102 瀏覽
添加回答
舉報
0/150
提交
取消