0

Hi I have a filter dropdown where subjects are listed as well as a search input, now what do I want is that every time a user will search anything he needs to first choose the subject which is mandatory and if he wants to type something in search, he can but then show only those records which belong to that subject only but I got stuck with my query as I am getting all of the records whether it belong to that subject or not.

This is what I have tried so far.


$SubjectReport = AssesmentReport::with(['assesment:id,assesment_name,description','curriculumUnit','subject'])->where('feedback', 'LIKE', "%{$search}%")->orWhere(DB::raw("(DATE_FORMAT(updated_at,'%d %M %Y'))"), 'LIKE', "%{$search}%")
                ->whereHas('subject', function($q) use ($filter){
                    $q->where('subject.id', $filter);
                })->orWhereHas('assesment', function($q) use ($search){
                    $q->where('assesment_name', 'LIKE', "%{$search}%")->orWhere('description', 'LIKE', "%{$search}%");
                })->orWhereHas('curriculumUnit', function($q) use ($search){
                    $q->where('unit_name', 'LIKE', "%{$search}%");
                })->where('user_id',Auth::user()->id)->orderBy('id', 'DESC')->get();

For ex- I have a subject of 'Maths' and I searched 'Report 1' then submit so it must show me all the records of 'Report 1' in subject 'Maths', but what do I got is 'Report 1' from 'Maths' and also from other subjects. Please help me how to solve this query?

Baby Babai
  • 197
  • 1
  • 10

0 Answers0