[英]Laravel Query Builder Eloquent
How can i make this query in Laravel?如何在 Laravel 中进行此查询?
SELECT GS_CONTRATOS.*,GS_ACESSOS.* from GS_CONTRATOS
full outer join GS_ACESSOS on GS_ACESSOS.CONTRATO_ID=GS_CONTRATOS.ID
where EMPRESA_ID='1' and (WEBUSER='ec' or WEBUSER is null)
i got my one like this and gives me 0 results, i have tried to use 2 wheres with varius variables but is not working because i cant get both of wheres.我得到了这样的结果并给了我 0 个结果,我尝试将 2 个 wheres 与 varius 变量一起使用,但不起作用,因为我无法同时获得两个 wheres。 i cant explain more than this bcs i dont even know how to make this query
我不能解释比这个 bcs 我什至不知道如何进行这个查询
She was suposed to give me all results in GS_ACESSO and all GS_CONTRATOS even if doesnt exist in one of them.她应该给我 GS_ACESSO 和所有 GS_CONTRATOS 中的所有结果,即使其中一个不存在。
$contratos = Contrato::query()
->join('GS_ACESSOS','GS_ACESSOS.CONTRATO_ID','=','GS_CONTRATOS.ID','full outer')
->where('GS_ACESSOS.WEBUSER','=',$id)->orWhere('EMPRESA_ID','=',$emp)
->get(['GS_CONTRATOS.*','GS_ACESSOS.*']);
When you want to add parenthesis, you must use the where condition with a closure.当您想添加括号时,您必须使用带有闭包的 where 条件。 There you go:
你去吧:
$contratos = Contrato::query()
->join('GS_ACESSOS','GS_ACESSOS.CONTRATO_ID','=','GS_CONTRATOS.ID','full outer')
->where('GS_ACESSOS.WEBUSER', $id)
->where(function ($q) use ($emp) {
$q->where('WEBUSER', 'ec')
->orWhere('EMPRESA_ID', $emp);
})
->get(['GS_CONTRATOS.*','GS_ACESSOS.*']);
Reference: https://laravel.com/docs/8.x/queries#logical-grouping参考: https : //laravel.com/docs/8.x/queries#logical-grouping
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.