You can find the answer in the documentation.
Dec 26, 2022
9
Level 4
Relational search filter
I have 3 tables "courses", "levels", and a pivot "course_level". The levels table has data like "Basic", "Intermediate", "Advanced"
Course model has this relation
public function level()
{
return $this->belongsToMany(Level::class);
}
The level mode has this relation
public function courses()
{
return $this->belongsToMany(Course::class);
}
How can I achieve this query by eloquent?
SELECT * from courses c
JOIN course_level cl
on cl.level_id = c.id
WHERE cl.level_id = 1 OR 2 OR 3;
Please or to participate in this conversation.