Added a validator that checks, if a values is empty, if another one is set.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class CustomValidator extends Validator
|
||||
{
|
||||
public function validateEmpty($attribute, $value)
|
||||
{
|
||||
return !$this->validateRequired($attribute, $value);
|
||||
}
|
||||
|
||||
public function validateEmptyIf($attribute, $value, $parameters)
|
||||
{
|
||||
$key = $parameters[0];
|
||||
|
||||
if ($this->validateRequired($key, $this->getValue($key))) {
|
||||
return $this->validateEmpty($attribute, $value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user