I have simple part of code to detect type of Discount, i added another type, but how to use operator OR
(||
) right way in this case ? ->where('taken', "N")
or "R"
do something.
this wont work ->where('taken', "N" || "R")
$code = Discount::where('code',$discount_code) ->where('expiry','>',Carbon::now()->toDateString()) ->where('subscription', $subscription) ->where('taken', "N") ->first();
Advertisement
Answer
in this case use whereIn()
and pass array to second parameter
-where('taken', "N" || "R")
to
whereIn('taken', ["N","R"])
so your final code will be
$code = Discount::where('code',$discount_code) ->where('expiry','>',Carbon::now()->toDateString()) ->where('subscription', $subscription) ->whereIn('taken', ["N","R"]) ->first();