我收到此錯誤 Undefined property: projekti 嘗試列印從資料庫中獲取的欄位時,這是導致錯誤的代碼
@foreach($dataOfProjects as $dp)
<div class="col-md-4 mt-2">
<h1 class="p-5 border border-3" >{{$dp->projekti}}</h1>
</div>
@endforeach
特別是`{{$dp->projekti}}
這是回傳 dataOfProjects 變數的控制器
public function specificClub(Request $request,$id){
$data = Clubs::find($id);
$dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);
$teachers = DB::table('mesuesit')->join('klubet','klubet.id','=','mesuesit.klubi_ne_kujdesari')->select('mesuesit.emri')->where('klubet.emri','=','rrobotike')->get();//Per te mare emrin e mesuesve te ketij klubi
return view('specificClub', compact('data','dataOfProjects','teachers'));
}
這是桌子 klubet

這是桌子專案

uj5u.com熱心網友回復:
將->get()多個結果或->first()一個結果添加到此行:
$dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);
從:
$dataOfProjects = DB::table('projektet') -> where('klubi', '=',$id);
至(對于多個結果):
$dataOfProjects = DB::table('projektet')->where('klubi', '=',$id)->get();
至(一個結果):
$dataOfProjects = DB::table('projektet')->where('klubi', '=',$id)->first();
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/446376.html
上一篇:無法創建表'student.#sql-f40_3'(錯誤號:150)
下一篇:如何在回圈中間重復值?
