简体   繁体   中英

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?

使用WhereIn

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM