Garden\Validation::status PHP Method

status() public method

The status code is an http resonse code and should be of the 4xx variety.
public status ( integer | null $value = null ) : Validation | integer
$value integer | null Pass a new status code or null to get the current code.
return Validation | integer Returns the current status code or $this for fluent sets.
    public function status($value = null)
    {
        if ($value !== null) {
            $this->status = $value;
            return $this;
        }
        if ($this->status) {
            return $this->status;
        }
        // There was no status so loop through the errors and look for the highest one.
        $maxStatus = 400;
        foreach ($this->errors as $field => $errors) {
            foreach ($errors as $error) {
                if (isset($error['status']) && $error['status'] > $maxStatus) {
                    $maxStatus = $error['status'];
                }
            }
        }
        return $maxStatus;
    }

Usage Example

 /**
  * Initialize an instance of the {@link ValidationException} class.
  *
  * @param Validation $validation The {@link Validation} object for the exception.
  */
 public function __construct(Validation $validation)
 {
     $this->validation = $validation;
     parent::__construct($validation->getMessage(), (int) $validation->status());
 }