7 months ago

Searching multiple fields over multiple tables

Posted 7 months ago by Sabbir345

I have 2 Tables: Users and HealthCheckup.

In the users table I hold information like their name, phone, address, etc. others hand health_checks table i hold info like BMI , prescription, anemia , doctor_name etc

My issue is when i am searching with One input field with this query work fine

$users = HealthCheckup::whereHas('user', function($query) use($search){ $query->Where('name', 'like', "%$search%"); })->orWhere('prescription', 'like', "%$search%") ->orderBy('id', 'DESC') ->with('user') ->paginate(20);

but when i am increasing multiple input with this query doesn't work properly

$users = HealthCheckup::whereHas('user', function($query) use($name){ $query->Where('name', 'like', "%$name%"); })->orWhere('prescription', 'like', "%$prescription%") ->orderBy('id', 'DESC') ->with('user') ->paginate(20);

Please sign in or create an account to participate in this conversation.