2 回答

TA貢獻1895條經驗 獲得超3個贊
//count qualified students who have father with id $fatherID
//problem lays here
$getSelectedStudent = \App\StudentRegistrars::where('status', 'Qualified')->whereHas('father_registrars', function($q) use($fatherID) {
$q->where('id', $fatherID);
})->count();
在$q->where('id', $fatherID);這里,“id”不明確,因為在您的連接查詢中,表father_registrars和student_registrars表都具有相同的列id。因此,在您的情況下,沒有表名的條件是導致不明確的原因。指定表名和列將解決您的問題。
所以在你的情況下,你的查詢應該是這樣的。
$getSelectedStudent = \App\StudentRegistrars::where('status', 'Qualified')->whereHas('father_registrars', function($q) use($fatherID) {
$q->where('father_registrars.id', $fatherID);
})->count();

TA貢獻1943條經驗 獲得超7個贊
在您正在執行的第一個 foreach 循環中...
$specificFather = \App\FatherRegistrars::where('id', $fatherID);
當你應該做類似的事情時
$specificFather = \App\FatherRegistrars::where('id', $fatherID)->first();
或者
$specificFather = \App\FatherRegistrars::findOrFail($fatherID);
同樣在第二個 foreach 中...
$fatherCredential = \App\User::where('username', $fatherUsername)->first();
- 2 回答
- 0 關注
- 187 瀏覽
添加回答
舉報