0

I am beginner in Laravel. In use in my project Laravel 5.8. I have this array:

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

and function:

public function getPaymentMethods(array $paymentId)
    {
            dd($paymentId);
            return PaymentSettings::where('id', '=', $paymentId)->get();
    }

It's not working because in $paymentId I have array. How can I change my code function to use with array (many where/orWhere)?

I need something like this (but in laravel eloquent):

SELECT * from payment_settings where id = 1 or id = 3 or id = 4 or id = 5.

2 Answers 2

1

You need whereIn,

return PaymentSettings::whereIn('id', $paymentId)->get();

Note: The whereIn method verifies that a given column's value is contained within the given array:

You can see detailed documentation here.

Sign up to request clarification or add additional context in comments.

Comments

0

where clause is not used to searche from array, whereIn is used. Usage -

return PaymentSettings::whereIn('id', $paymentId)->get();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.