Level 41
You might want to try this:
return Equipment::where('slug', $slug)
->with(['users.employee' => function ($query) {
$query->where('active', 1);
}])->first();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Equipment has many users. Users attach to one employee.
This query is returning 'active' for the equipment, not the employee. I need only active employees to show, but still return the equipment info if none exists.
return Equipment::where('slug', $slug)
->with(['users' => function ($query) {
$query->with(['employee' => function ($q) {
$q->where('active', 1);
}]);
}])->first();
Please or to participate in this conversation.