Yoanna Murdzheva
Yoanna Murdzheva

Reputation: 259

Not getting the id in where clause - Laravel 5.2

I need to get the record with special id and i have this in my method :

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()
    ]);
}

When i do dd(ClassSubject::where('teacher_id', $user->id)->pluck('id','subject_id')); i see that I'm getting the information that i need, but when i do dd(StudentMark::where('subject_id', $subject)->get()); it returns an empty array.

Any idea why?

Upvotes: 1

Views: 106

Answers (2)

oseintow
oseintow

Reputation: 7421

Change it to (whereIn)

 'marks' => StudentMark::whereIn('subject_id', $subject)->get()

and let see what hapens

Upvotes: 1

Jilson Thomas
Jilson Thomas

Reputation: 7313

In $subjectyou have id and subject_id. You might wanna just take subject_id.

So change this: StudentMark::where('subject_id', $subject)->get()

to

StudentMark::where('subject_id', $subject[1])->get()

Upvotes: 1

Related Questions