【问题标题】:LARAVEL use Lists result as a parameterLARAVEL 使用列表结果作为参数
【发布时间】:2015-04-06 12:01:12
【问题描述】:

我需要一些帮助才能在 laravel 中进行此查询。

Select id from tableone where id in (1,2,3,4,5)

(1,2,3,4,5) 必须是另一个查询的结果。

 This >>> $s = TableOne::lists('id');
 Result >>> ["4","14", "11", "1", "13", "3", "2"]

我该怎么做?

【问题讨论】:

  • 在 Laravel 5.3 中 lists 将被弃用。它已重命名为pluck。请改用pluck 以进行将来的校对。

标签: php sql laravel eloquent


【解决方案1】:

你可以在 Laravel 中使用wherein 函数。

$s = AnotherTable::lists('id'); // get ids from another query
$users = TableOne::whereIn('id', $s)->get(); // pass array of ids into it

欲了解更多信息:http://laravel.com/docs/5.0/queries#selects

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    相关资源
    最近更新 更多