LARAVEL使用Lists结果作为参数


LARAVEL use Lists result as a parameter

我需要一些帮助才能在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中使用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