Try using orWhereRaw:
->orWhereRaw("group_concat(value SEPARATOR '') LIKE ?", [$value])
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have following MySQL query
SELECT employee_id, GROUP_CONCAT(`value` SEPARATOR '') AS 'phone'
FROM employee_contacts
where channel='phone_dial' or channel='phone_number' GROUP BY employee_id
and I need to run this inside this code block, but getting syntax error.
$this->builder
->where(function ($query) use ($value) {
collect($value)->each(function ($value, $index) use ($query) {
$method = 'orWhere';
if ($index === 0) {
$method = 'where';
}
$query->$method(function ($query) use ($value) {
$value = '%' . $value . '%';
$query->orWhereHas('contacts', function ($query) use ($value) {
$query->where('channel', 'email')->where('value', 'LIKE', $value); // this is working fine, and everthing up to this point
//here I need to continue with orWhere with the MySQL query above and run
->where('value', 'LIKE', $value) at the end.
// I can run this without syntax errors
$query->select('employee_id', DB::raw("group_concat(value SEPARATOR '') as phone"))
->where('channel', 'phone_dial')->orWhere('channel', 'phone_number')
->groupBy('employee_id')
//but I will need something like:
$query->orWhere(some valid syntax to get phone value)->where('phone', 'LIKE', $value);
}
});
});
});
The code might not be exactly but hopefully you can get an idea. I will appreciate any suggestions. Thanks!
Please or to participate in this conversation.