I'm trying to build a small query module and have hit an issue. I read this article and have implemented something similar where I'm trying to search through a related model using Builder:
public function filter(Request $request, City $city)
{
$city = $city->newQuery();
// Search for a city based on its state.
if ($request->has('state')) {
$city->whereHas('state', function ($query) use ($request) {
$query->where('state', $request->state);
});
}
This doesn't trigger an error, it just returns an empty object.