Reputation: 663
Trying to search Patient record from three tables in a filter...I have already write the code for patient name and patient phone but got stuck at area of treatment and doctor because both of them are in different table..Please help to write a query for this filter...
Here is my filter:
Patient Data along with billing(doctor and area of treatment):
Patient Model:
public function scopeQueryStringFilters( $query )
{
if(request()->has('patient_name'))
{
$query->where('name',request('patient_name'));
}
if(request()->has('patient_phone'))
{
$query->where('phone',request('patient_phone'));
}
}
Upvotes: 0
Views: 378
Reputation: 594
You can use whereHas method.
Patient::whereHas('billing', function($query){
$query->where('area_of_treatment_id', request('area_of_treatment_id'));
})
->get();
Patient::whereHas('billing.doctor', function($query){
$query->where('name', request('doctor'));
})
->get();
Upvotes: 1