2
 $transactionType = ['request','transfer'];
 $transactions = Transaction::where(function ($query) use 
($request) {
    if (in_array("request", $transactionType))) {
        return $query->where('transactionType', 'request');
    }
    if (in_array("transfer", $transactionType)) {
        return $query->where('transactionType', 'transfer');
    }
})->get();

I want it to return both returns as $transaction contain both element 'transfer' and 'request' but it is returning only $query->where('transactionType', 'request');

2
  • Hey Aman, are you trying to get records for both the transaction types together ? Commented Nov 1, 2021 at 7:29
  • yes buddy, but only when $transactionType array has both 'request' and 'transfer' Commented Nov 1, 2021 at 7:31

1 Answer 1

1

Maybe this is what you're looking for,

 $transactionType = ['request','transfer'];
 $transactions = Transaction::whereIn('transactionType', $transactionType)->get();
Sign up to request clarification or add additional context in comments.

1 Comment

oh my god , I knew about whereIn clause in laravel, but I didn't think to use it. Thankyou @groovy_guy, you're a time saver. Thankyou chellam sir

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.