src/ResourceValidationsTrait.php
protected function validateRelatedResourceExists($field, \CFX\JsonApi\ResourceInterface $r, $required = true)
    {
        if ($r !== null) {
            try {
                $r->initialize();
                $result = true;
            } catch (ResourceNotFoundException $e) {
                $result = false;
            }
        } else {
            $result = !$required;
        }

        if ($result) {
            $this->clearError($field, 'exists');
            return true;
        } else {
            $this->setError($field, 'exists', [
                "title" => "Invalid Relationship `$field`",
                "detail" => "The `$field` you've indicated for this order is not currently in our system."
            ]);
            return false;
        }
    }
protected function validateRelatedResourceExists($field, \CFX\JsonApi\ResourceInterface $r, $required = true)
    {
        if ($r !== null) {
            try {
                $r->initialize();
                $result = true;
            } catch (ResourceNotFoundException $e) {
                $result = false;
            }
        } else {
            $result = !$required;
        }

        if ($result) {
            $this->clearError($field, 'exists');
            return true;
        } else {
            $this->setError($field, 'exists', [
                "title" => "Invalid Relationship `$field`",
                "detail" => "The `$field` you've indicated for this order is not currently in our system."
            ]);
            return false;
        }
    }
protected function validateRelatedResourceExists ( $ field , \ CFX \ JsonApi \ ResourceInterface $ r , $ required = true ) { if ( $ r !== null ) { try { $ r -> initialize ( ) ; $ result = true ; } catch ( ResourceNotFoundException $ e ) { $ result = false ; } } else { $ result = ! $ required ; } if ( $ result ) { $ this -> clearError ( $ field , 'exists' ) ; return true ; } else { $ this -> setError ( $ field , 'exists' , [ "title" => "Invalid Relationship `$field`" , "detail" => "The `$field` you've indicated for this order is not currently in our system." ] ) ; return false ; } }
Validates that the given resource actually exists in the database

@param string $field The name of the field (attribute or relationship) being validated
@param \CFX\JsonApi\ResourceInterface $r The resource to validate
@param bool $required Whether or not the resource is required (this affects how `null` is handled)
@return bool Whether or not the validation has passed
Validates that the given resource actually exists in the database