samedi 28 décembre 2019

How to validate 2 Laravel fields in a NAND way

I'm looking for a solution to the following case: my controller action receives 2 variables, however they must exclude eachother. So you can pass either 1 of them or none.

The following truth table arises (NAND):

| A | B | Result |
|---|---|--------|
| 0 | 0 |   1    |
| 0 | 1 |   1    |
| 1 | 0 |   1    |
| 1 | 1 |   0    |

(say A equals points and B equals coupon).

// MyController.php
$this->validate($request, [
    'points' => '',
    'coupon' => ''
]);

I've tried some solutions like nullable|required_without:field_name but those seem to result in an XOR, which means you must pass at least 1 of them.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/366MyRE
via IFTTT

Aucun commentaire:

Enregistrer un commentaire