0

i have an array like this :

array:2 [▼
0 => 1
1 => 2
]

and i have product table like this :

"id" => 1
    "nama" => "product1"
    "harga" => 100000
    "created_at" => "2021-05-01 15:21:08"
    "updated_at" => "2021-05-01 15:21:08"
  ]
"id" => 2
    "nama" => "product2"
    "harga" => 90000
    "created_at" => "2021-05-01 15:21:08"
    "updated_at" => "2021-05-01 15:21:08"
  ]
"id" => 3
    "nama" => "product3"
    "harga" => 80000
    "created_at" => "2021-05-01 15:21:08"
    "updated_at" => "2021-05-01 15:21:08"
  ]
 
 and more ...

i want to find product data using where id with multiple input, example :

array:2 [▼
0 => 1
1 => 2
]

the result : 

"id" => 1
"nama" => "product1"
"harga" => 100000
"created_at" => "2021-05-01 15:21:08"
"updated_at" => "2021-05-01 15:21:08"
]
 "id" => 2
 "nama" => "product2"
 "harga" => 90000
 "created_at" => "2021-05-01 15:21:08"
 "updated_at" => "2021-05-01 15:21:08"
 ]

is it possible? very happy when someone hepl and tell me how, thanks.

1 Answer 1

2

You can use whereIn from Query Builder. see Docs

$users = DB::table('users')
             ->whereIn('id', [1, 2, 3])
             ->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.