Level 102
What error are you getting?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
need help with this nested closure function as it is not working perfectly. This chunk of code is part of a bigger sql query , and problem lies in this part only any help will be appreciated
$browse_verticals = $browse_verticals->distinct()->with("verticals")->with([
"document_types" => $closure = function ($query) use ($document_array, $key) {
$query->whereIn('document_type_id', $document_array);
if ($key != "") {
//problem is here it is working fine for above statement but not for this key .
$query->whereHas(
'titles',
function ($query) use ($key) {
$query->orwhere("title", 'LIKE', '%' . $key . '%');
}
);
}
}
])->whereHas('document_types', $closure)->distinct();
Please or to participate in this conversation.