Level 88
What is the error you get?
Anyway, your query should look like this
$user= Users::with('address.photo', function (Builder $query) {
$query->where('description', 'like', '%nice%');
})->paginate(5);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
id name address_id
id photo_id
id description
I need to get all user which has photo description ="nice" whats the correct Eloquent to get the result
$user= Users::with('address.photo', function (Builder $query) { $query->where('photo.description', 'like', 'nice'); } )->paginate(5);
I need to get all user which has photo description ="nice"
then you need to use whereHas to query by a relation.
Please or to participate in this conversation.