【问题标题】:How to Convert Working Query into Eloquent Lumen config如何将工作查询转换为 Eloquent Lumen 配置
【发布时间】:2020-11-03 03:02:07
【问题描述】:

亲爱的,

我有这个工作查询来从两个 pgsql 表中检索令牌和 appid 信息。我正在尝试使用 Lumen 框架来实现 API。如何将此查询转换为雄辩的陈述?因此可以配置控制器部分。我试过这个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);

【问题讨论】:

    标签: php sql laravel eloquent lumen


    【解决方案1】:

    你可以这样做。

    $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();
    

    但是看看上面的查询,如果我们继续像这样的完整原始查询,这似乎是一个不错的选择

    $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);");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-14
      • 2013-01-08
      相关资源
      最近更新 更多