Im lost in if
, else
statments and cant figure out right syntax with obviously simple problem.
i have 3 situations, code
which i looking for is saved in DTB, OR hardcoded and code start CODE_1-
OR no code
at all.
first defined variable $code
$code = Discount::where('code',$discount_code)
1] lets check if variable $code
is in database or return 0
if (!is_null($code) !== false){
$response['discount'] = $code->discount;
} else {
$response['valid'] = false;
$response['discount'] = 0;
2] variable isnt in DTB but is hardcoded CODE_1-
this type of codes always start at CODE_1-
so function strpos
can help
and there start my problem, code
isnt in datebase
if (is_null($code) = (strpos($discount_code, 'CODE-')) {
$response['valid'] = true;
$response['discount'] = 50;
3] Code
isnt hardoced or saved in databese
?
can be all this conditions merged together ?
Aucun commentaire:
Enregistrer un commentaire