Jade Baribar
Jade Baribar

Reputation: 81

LARAVEL use Lists result as a parameter

I need some help to do this query in laravel.

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

The (1,2,3,4,5) must be a result from another query.

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

How do I do this?

Upvotes: 2

Views: 284

Answers (1)

mininoz
mininoz

Reputation: 5958

You can use wherein function in Laravel.

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

For more information: http://laravel.com/docs/5.0/queries#selects

Upvotes: 1

Related Questions