diff --git a/app/Filters/ExpenseFilters.php b/app/Filters/ExpenseFilters.php index ac54ac9d7502..8992424d59f6 100644 --- a/app/Filters/ExpenseFilters.php +++ b/app/Filters/ExpenseFilters.php @@ -38,9 +38,11 @@ class ExpenseFilters extends QueryFilters return $this->builder->where(function ($query) use ($filter) { $query->where('expenses.name', 'like', '%'.$filter.'%') ->orWhere('expenses.id_number', 'like', '%'.$filter.'%') - ->orWhere('expense_contacts.first_name', 'like', '%'.$filter.'%') - ->orWhere('expense_contacts.last_name', 'like', '%'.$filter.'%') - ->orWhere('expense_contacts.email', 'like', '%'.$filter.'%') + ->orWhereHas('contacts', function ($query) use($filter){ + $query->where('expense_contacts.first_name', 'like', '%'.$filter.'%'); + $query->orWhere('expense_contacts.last_name', 'like', '%'.$filter.'%'); + $query->orWhere('expense_contacts.email', 'like', '%'.$filter.'%'); + }) ->orWhere('expenses.custom_value1', 'like', '%'.$filter.'%') ->orWhere('expenses.custom_value2', 'like', '%'.$filter.'%') ->orWhere('expenses.custom_value3', 'like', '%'.$filter.'%') diff --git a/app/Filters/VendorFilters.php b/app/Filters/VendorFilters.php index 231bc4f5e80f..0dafbb589d8c 100644 --- a/app/Filters/VendorFilters.php +++ b/app/Filters/VendorFilters.php @@ -38,9 +38,11 @@ class VendorFilters extends QueryFilters return $this->builder->where(function ($query) use ($filter) { $query->where('vendors.name', 'like', '%'.$filter.'%') ->orWhere('vendors.id_number', 'like', '%'.$filter.'%') - ->orWhere('vendor_contacts.first_name', 'like', '%'.$filter.'%') - ->orWhere('vendor_contacts.last_name', 'like', '%'.$filter.'%') - ->orWhere('vendor_contacts.email', 'like', '%'.$filter.'%') + ->orWhereHas('contacts', function ($query) use($filter){ + $query->where('vendor_contacts.first_name', 'like', '%'.$filter.'%'); + $query->orWhere('vendor_contacts.last_name', 'like', '%'.$filter.'%'); + $query->orWhere('vendor_contacts.email', 'like', '%'.$filter.'%'); + }) ->orWhere('vendors.custom_value1', 'like', '%'.$filter.'%') ->orWhere('vendors.custom_value2', 'like', '%'.$filter.'%') ->orWhere('vendors.custom_value3', 'like', '%'.$filter.'%')