Not quite 100% sure but i think you are looking for something like this:
$students= Student::where('id', 5)
->whereHas('havecourse', function ($query) {
$query->where('course_name', 'like', '%BC%');
})->get()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
If there are two table student and course , Now if i want to use like query in course after relation with student. eg Student::where(id,5)->with("havecourse")->where('course_name','LIKE','%'.'BC','%')->get()
How to do that thanks.
Please or to participate in this conversation.