-2

I am using laravel 5 and having following array:

    array:3 [▼
  0 => 3,
  1 => 4,
  2 => 5
]

Now i wanted to get all values/rows from table say 'X' having id's 3,4,5

Kapil Verma
  • 178
  • 3
  • 17
  • 4
    Using a [whereIn()](https://laravel.com/docs/5.1/queries) perhaps? The Laravel documentation is there for you to read for yourself – Mark Baker Jun 02 '16 at 11:15
  • 1
    Can you post your complete code pls ? – Sofiene Djebali Jun 02 '16 at 11:16
  • @Mark Baker Can't we use relations ? – Kapil Verma Jun 02 '16 at 11:17
  • What have relations got to do with this? Unless there's something you haven't said in your question, then this has nothing to do with relations, because you're talking about a single model (`X`), and simply retrieving values from that where the id is in your array – Mark Baker Jun 02 '16 at 11:19
  • Your using of the words "table" and "id" without any apparent relevant information on what that means is very confusing. – apokryfos Jun 02 '16 at 11:22

2 Answers2

1

Try this query

$array = [ 0 => 3,1 => 4, 2 => 5];

$results = DB::table('x')
                    ->whereIn('id',$array)
                    ->get();
srinivas
  • 109
  • 12
0

You can see the query sample for Laravel 5

  $result=DB::table('x')->whereIn('id',[3,4,5])->get();
Majbah Habib
  • 8,058
  • 3
  • 36
  • 38