Mysql Laravel 5.1雄辩的orWhere子查询

Mysql Laravel 5.1雄辩的orWhere子查询,mysql,laravel,eloquent,Mysql,Laravel,Eloquent,我被这个问题弄糊涂了。我真的需要这方面的帮助: SELECT COUNT(*) FROM customers WHERE (SELECT count(*) FROM customerEmails WHERE email = :email) > 0 OR (SELECT count(*) FROM customerPhoneNumbers WHERE phoneNumber = :cellphone) > 0 OR cellphone = :cellphone OR email

我被这个问题弄糊涂了。我真的需要这方面的帮助:

SELECT COUNT(*) FROM customers
WHERE (SELECT count(*) FROM customerEmails WHERE email = :email) > 0 
OR (SELECT count(*) FROM customerPhoneNumbers WHERE phoneNumber = :cellphone) > 0 
OR cellphone = :cellphone 
OR email = :email
我不知道什么应该是有说服力的代码。蒂亚

根据客户与其他实体之间的关系,您可以使用Eloquent(略高于锚定)方法有条件地加载客户。假设您有一个名为
Customer
的模型,您可以尝试:

$count = Customer::whereHas('customerEmails', function ($query) use ($email){
    $query->where('email', $email);
})
->orWhereHas('customerPhoneNumbers', function ($query) use ($cellphone){
    $query->where('phoneNumber', $cellphone);
})
->orWhere('cellphone', $cellphone)
->orWhere('email', $email)
->count();

你在利用关系吗?并提供所需表的正确架构。您的查询在编写时不是有效的sql。你不可能让拉威尔产生这样的结果。