How to make multiplicatio in Laravel?

There is such task:
term_installments - first_payment If not 100 then between:0,12
term_installments - If resource_id is = 154 then between:0,60
Tobish in one test, you need to specify 2 bitwine.
July 2nd 19 at 13:10
2 answers
July 2nd 19 at 13:12
Solution
AppServiceProvider (though these things I make a separate ValidatorServiceProvider) in the method boot.
As I understand it, you need to first check resource_id is then first_payment.
The idea is simple, the implementation for You.

\Validator::extend('your_rule_name', function ($attr, $value, $params, \Illuminate\Validation\Validator $validator) {
 // request data
 $data = $validator->getData();

 if (array_get($data, 'resource_id is') === 154) {
 return $value >= 0 && $value <= 60;
}

 if (array_get($data, 'first_payment') !== 100) {
 return $value >= 0 && $value <= 12;
}

 return false;
});
Thank you, it really is) - deanna49 commented on July 2nd 19 at 13:15
July 2nd 19 at 13:14
So as not to create a rule every time you can make it easier:

$validator = Validator::make(...);

$validator->after(function ($validator) {
 if ($this->somethingElseIsInvalid()) {
 $validator->errors()->add('field', 'Something is wrong with this field!');
}
});

if ($validator->fails()) {
//
}


That is after the basic rules are checked, to check and something else :)
Code can be any there.

Find more questions by tags PHPLaravel