Reputation: 81
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
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