Esensi\Model\Traits\RelatingModelTrait::callRelationship PHP Method

callRelationship() protected method

Proxy call a relationship method using the configuration arguments of the relationship.
protected callRelationship ( string $name ) : mixed
$name string of related model
return mixed
    protected function callRelationship($name)
    {
        // Get the relationship arguments
        $args = $this->getRelationship($name);
        // Build the relationship
        $method = array_shift($args);
        $relationship = call_user_func_array([$this, $method], $args);
        // Check to see if this relationship has extended pivot attributes
        if ($this->hasPivotAttributes($name)) {
            // Add timestamps to relationship
            $attributes = $this->getPivotAttributes($name);
            if (in_array('timestamps', $attributes)) {
                unset($attributes[array_search('timestamps', $attributes)]);
                $relationship->withTimestamps();
            }
            // Add the pivot attributes to the relationship
            $relationship->withPivot($attributes);
        }
        return $relationship;
    }