# wpide/3.5.9/vendor/rakit/validation/src/Rules/RequiredUnless.php

WPIDE – File Manager &amp; Code Editor, version 3.5.9. 53 lines.

- Page: https://pluginprobe.com/plugins/wpide/3.5.9/code/vendor/rakit/validation/src/Rules/RequiredUnless.php
- Raw: https://pluginprobe.com/plugins/wpide/3.5.9/raw/vendor/rakit/validation/src/Rules/RequiredUnless.php
- Modified: 2022-07-30T20:33:10+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/wpide/3.5.9/code/vendor/rakit/validation/src/Rules/RequiredUnless.php#L10-L20`.

```php
<?php

namespace Rakit\Validation\Rules;

use Rakit\Validation\Rule;

class RequiredUnless extends Required
{
    /** @var bool */
    protected $implicit = true;

    /** @var string */
    protected $message = "The :attribute is required";

    /**
     * Given $params and assign the $this->params
     *
     * @param array $params
     * @return self
     */
    public function fillParameters(array $params): Rule
    {
        $this->params['field'] = array_shift($params);
        $this->params['values'] = $params;
        return $this;
    }

    /**
     * Check the $value is valid
     *
     * @param mixed $value
     * @return bool
     */
    public function check($value): bool
    {
        $this->requireParameters(['field', 'values']);

        $anotherAttribute = $this->parameter('field');
        $definedValues = $this->parameter('values');
        $anotherValue = $this->getAttribute()->getValue($anotherAttribute);

        $validator = $this->validation->getValidator();
        $requiredValidator = $validator('required');

        if (!in_array($anotherValue, $definedValues)) {
            $this->setAttributeAsRequired();
            return $requiredValidator->check($value, []);
        }

        return true;
    }
}

```
