我只是在它調用的刀片中遇到錯誤此集合實例上不存在屬性 [img_pers]。(視圖:C:\xampp\htdocs\AppGestion\resources\views\frontend\etat_civil.blade.php)我的控制器代碼: public function index() { $listpers = Personne::all(); return view('frontend.etat_list', ['personnes' => $listpers]); }代碼視圖:<img class="card-img-top" src="{{ asset('storage/avatars/'.$personnes->img_pers) }}" class="img-thumbnail" style="height:300;" />商店功能: public function insert(Request $request) { $image = time().'.'.$request->file('img_pers')->extension(); $path = $request->file('img_pers')->storeAs('avatars',$image); $pers = new Personne(); $pers->img_pers = $image; $pers->save(); return redirect('etat_lists'); }
1 回答

函數式編程
TA貢獻1807條經驗 獲得超9個贊
你正在返回所有的人。它們以集合數組的形式出現。您將該數組提供給您的視圖,但您嘗試訪問該數組的屬性。這是不可能的,您需要先獲取數組中的一項,然后再訪問該屬性:
$personnes->first()->img_pres
查看Collections
文檔以獲取有關集合的更多信息。
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消