Appzcoder\CrudGenerator\Commands\CrudModelCommand::createRelationshipFunction PHP Method

createRelationshipFunction() protected method

Create the code for a model relationship
protected createRelationshipFunction ( string &$stub, string $relationshipName, string $relationshipType, $argsString )
$stub string
$relationshipName string the name of the function, e.g. owners
$relationshipType string the type of the relationship, hasOne, hasMany, belongsTo etc
    protected function createRelationshipFunction(&$stub, $relationshipName, $relationshipType, $argsString)
    {
        $code = "public function " . $relationshipName . "()\n\t{\n\t\t" . "return \$this->" . $relationshipType . "(" . $argsString . ");" . "\n\t}";
        $str = '{{relationships}}';
        $stub = str_replace($str, $code . "\n\t{$str}", $stub);
        return $this;
    }