我需要获取具有特殊ID的记录,我在我的方法中有这个:
public function addedMark()
{
$user = Auth::user();
$subject = ClassSubject::where('teacher_id', $user->id)->pluck('id','subject_id');
return view('educator.account.marks', [
'user' => $user,
'marks' => StudentMark::where('subject_id', $subject)->get()
]);
}
当我dd(ClassSubject::where('teacher_id', $user->id)->pluck('id','subject_id'));
时,我发现我得到了我需要的信息,但当我dd(StudentMark::where('subject_id', $subject)->get());
时,它会返回一个空数组。
知道为什么吗?
答案 0 :(得分:1)
在$subject
中,您有id
和subject_id
。你可能想要subject_id
。
所以改变一下:StudentMark::where('subject_id', $subject)->get()
到
StudentMark::where('subject_id', $subject[1])->get()
答案 1 :(得分:1)
将其更改为(whereIn)
'marks' => StudentMark::whereIn('subject_id', $subject)->get()
让我们看看hapens