| 1 |
<?php |
| 2 |
|
| 3 |
namespace Rakit\Validation\Rules; |
| 4 |
|
| 5 |
use Rakit\Validation\Rule; |
| 6 |
|
| 7 |
class RequiredWithAll extends Required |
| 8 |
{ |
| 9 |
/** @var bool */ |
| 10 |
protected $implicit = true; |
| 11 |
|
| 12 |
/** @var string */ |
| 13 |
protected $message = "The :attribute is required"; |
| 14 |
|
| 15 |
/** |
| 16 |
* Given $params and assign $this->params |
| 17 |
* |
| 18 |
* @param array $params |
| 19 |
* @return self |
| 20 |
*/ |
| 21 |
public function fillParameters(array $params): Rule |
| 22 |
{ |
| 23 |
$this->params['fields'] = $params; |
| 24 |
return $this; |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Check the $value is valid |
| 29 |
* |
| 30 |
* @param mixed $value |
| 31 |
* @return bool |
| 32 |
*/ |
| 33 |
public function check($value): bool |
| 34 |
{ |
| 35 |
$this->requireParameters(['fields']); |
| 36 |
$fields = $this->parameter('fields'); |
| 37 |
$validator = $this->validation->getValidator(); |
| 38 |
$requiredValidator = $validator('required'); |
| 39 |
|
| 40 |
foreach ($fields as $field) { |
| 41 |
if (!$this->validation->hasValue($field)) { |
| 42 |
return true; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
$this->setAttributeAsRequired(); |
| 47 |
return $requiredValidator->check($value, []); |
| 48 |
} |
| 49 |
} |
| 50 |
|