简体   繁体   English

如何将工作查询转换为 Eloquent Lumen 配置

[英]How to Convert Working Query into Eloquent Lumen config

Dears,亲爱的,

I have this working query to retrieve token and appid information from two pgsql tables.我有这个工作查询来从两个 pgsql 表中检索令牌和 appid 信息。 I am trying to implement an API by using Lumen framework.我正在尝试使用 Lumen 框架来实现 API。 How can i convert this query to eloquent statements?如何将此查询转换为 eloquent 语句? So its possible to configure controller section.因此可以配置 controller 部分。 I have tried this http://cryptic-peak-77605.herokuapp.com/ but without succes我试过这个http://cryptic-peak-77605.herokuapp.com/但没有成功

SELECT token,appid FROM db.public.tokens WHERE id = (SELECT id FROM db.public.data WHERE (name,value) IN (('userName', '100'), ('domain', '1591.xpto.xyz' )) group by id having count(distinct VALUE) = 2);

You can do something like this.你可以做这样的事情。

$records = YourModel::where('id', DB::select("SELECT id FROM data WHERE (name,value) IN (('userName', '100'), ('domain', '1591.xpto.xyz' )) group by id having count(distinct VALUE) = 2"))->select(['token', 'appid'])->get();

But looking at the above query it seems that it would be a good choice if we would proceed with a complete raw query like但是看看上面的查询,如果我们继续一个完整的原始查询,这似乎是一个不错的选择,比如

$records = DB::select("SELECT token,appid FROM tokens WHERE id = (SELECT id FROM data WHERE (name,value) IN (('userName', '100'), ('domain', '1591.xpto.xyz' )) group by id having count(distinct VALUE) = 2);");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM