Chukwuebuka
Chukwuebuka

Reputation: 412

laravel eloquent where method

I have a courses table I want to query like this :

semesters = [5,3,7];

$class_id = 3;

Course::where(['class_id' => $class_id, 'semester_id' => $semesters ])->get();

where $semesters must be an array. so I want to get the collection of courses where class_id is 3 and where semester_id is 5,3,7. however it gets the collection of only the first index of the $semester array. how do I get the collection of all the values of that $semester array?

Upvotes: 0

Views: 186

Answers (1)

VIKAS KATARIYA
VIKAS KATARIYA

Reputation: 6005

Use WhereIn

Course::whereIn('semester_id', $semesters)->where('semester_id', $semesters)->get();

Upvotes: 1

Related Questions