$query->whereHas('patient', function ($q) use ($name) { $q->from('cbfy_home.patients')->where('name', 'like', "%$name%");});