2

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?

  • In Laravel 5.3 `lists` will be deprecated. It has been renamed to `pluck`. Use `pluck` instead for future proofing. – DutGRIFF Jan 15 '16 at 15:44

1 Answers1

1

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

mininoz
  • 5,908
  • 4
  • 23
  • 23