Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

FounderStartup's avatar

Getting error in a nested query : Exception Property [individual] does not exist on the Eloquent builder instance.

Getting this error.

 $listings = Listings::with('project.city','user','project.locality')
            ->whereHas('project.city', function ($query) {$query->where('status', 1);})
            ->where ('status', '1')
            ->whereIn('listingtype', [$forsale, $buyers, $forrent, $lookingtorentout])
            ->when($request->bedrooms, function ($query) use ($request)
                {$query->whereIn('bhk', [$request->bedrooms ]);})
            ->whereHas('user', function ($request) {$request
							->whereIn('role', [$request->individual, $request->broker]);})
            ->latest()
            ->paginate(5)
            ->withQueryString();

I am trying to filter listings based on few filters. The error is due to filtering of listings by an individual or broker. Listings are related to 'User" and 'user' has two type of 'role'.

0 likes
2 replies
kevinbui's avatar
kevinbui
Best Answer
Level 41

This is the line that cause the problem:

 ->whereHas('user', function ($request) {$request
							->whereIn('role', [$request->individual, $request->broker]);})

You might want to do this:

...
 ->whereHas('user', function ($query) use ($request) {
    $query->whereIn('role', [$request->individual, $request->broker]);
})
...
1 like

Please or to participate in this conversation.