| 1 |
<?php |
| 2 |
|
| 3 |
namespace Rakit\Validation\Rules; |
| 4 |
|
| 5 |
use Rakit\Validation\Rule; |
| 6 |
|
| 7 |
class Present extends Rule |
| 8 |
{ |
| 9 |
/** @var bool */ |
| 10 |
protected $implicit = true; |
| 11 |
|
| 12 |
/** @var string */ |
| 13 |
protected $message = "The :attribute must be present"; |
| 14 |
|
| 15 |
/** |
| 16 |
* Check the $value is valid |
| 17 |
* |
| 18 |
* @param mixed $value |
| 19 |
* @return bool |
| 20 |
*/ |
| 21 |
public function check($value): bool |
| 22 |
{ |
| 23 |
$this->setAttributeAsRequired(); |
| 24 |
|
| 25 |
return $this->validation->hasValue($this->attribute->getKey()); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Set attribute is required if $this->attribute is set |
| 30 |
* |
| 31 |
* @return void |
| 32 |
*/ |
| 33 |
protected function setAttributeAsRequired() |
| 34 |
{ |
| 35 |
if ($this->attribute) { |
| 36 |
$this->attribute->setRequired(true); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|