protected function getMethodCallsForForeignKeys()
    {
        $methods = [];

        if ($keys = $this->getForeignKeys()) {
            /** @var ForeignKey $key */
            foreach ($keys as $key) {
                $relatedTable = $key->getRelatedTable();
                $relatedModel = '\\' . $this->getAppNamespace() . $relatedTable->getModelName() . '::class';

                if ($key->isSource()) {
                    $methodName = lcfirst($key->isForMany() ? $relatedTable->getName() : $relatedTable->getModelName());

                    $methodReturnSuffix = 'has' . ($key->isForMany() ? 'Many' : 'One');
                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // if
                elseif ($key->isForPivotTable()) {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsToMany';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // elseif
                else {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsTo';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel}, '{$key->foreign}');";
                } // else

                $methodName = preg_replace_callback(
                    '/(_[a-z])/',
                    function ($matches) {
                        return strtoupper(substr($matches[0], 1));
                    },
                    $methodName
                );

                $method = "\t/**\n\t * Getter for {$relatedTable->getName()}.\n\t " .
                    "* @return \\Illuminate\\Database\\Eloquent\\Relations\\" .
                    ucfirst($methodReturnSuffix) . " \n\t */\n\t" .
                    "public function {$methodName}()\n\t{\n\t\t{$methodContent}\n\t}";

                $methods[] = $method;
            } // foreach
        } // if

        return array_unique($methods);
    }
protected function getMethodCallsForForeignKeys()
    {
        $methods = [];

        if ($keys = $this->getForeignKeys()) {
            /** @var ForeignKey $key */
            foreach ($keys as $key) {
                $relatedTable = $key->getRelatedTable();
                $relatedModel = '\\' . $this->getAppNamespace() . $relatedTable->getModelName() . '::class';

                if ($key->isSource()) {
                    $methodName = lcfirst($key->isForMany() ? $relatedTable->getName() : $relatedTable->getModelName());

                    $methodReturnSuffix = 'has' . ($key->isForMany() ? 'Many' : 'One');
                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // if
                elseif ($key->isForPivotTable()) {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsToMany';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});";
                } // elseif
                else {
                    $methodName = lcfirst($key->isForMany() && $key->isForPivotTable()
                        ? $relatedTable->getName()
                        : $relatedTable->getModelName());

                    $methodReturnSuffix = 'belongsTo';

                    $methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel}, '{$key->foreign}');";
                } // else

                $methodName = preg_replace_callback(
                    '/(_[a-z])/',
                    function ($matches) {
                        return strtoupper(substr($matches[0], 1));
                    },
                    $methodName
                );

                $method = "\t/**\n\t * Getter for {$relatedTable->getName()}.\n\t " .
                    "* @return \\Illuminate\\Database\\Eloquent\\Relations\\" .
                    ucfirst($methodReturnSuffix) . " \n\t */\n\t" .
                    "public function {$methodName}()\n\t{\n\t\t{$methodContent}\n\t}";

                $methods[] = $method;
            } // foreach
        } // if

        return array_unique($methods);
    }
protected function getMethodCallsForForeignKeys ( ) { $ methods = [ ] ; if ( $ keys = $ this -> getForeignKeys ( ) ) { /** @var ForeignKey $key */ foreach ( $ keys as $ key ) { $ relatedTable = $ key -> getRelatedTable ( ) ; $ relatedModel = '\\' . $ this -> getAppNamespace ( ) . $ relatedTable -> getModelName ( ) . '::class' ; if ( $ key -> isSource ( ) ) { $ methodName = lcfirst ( $ key -> isForMany ( ) ? $ relatedTable -> getName ( ) : $ relatedTable -> getModelName ( ) ) ; $ methodReturnSuffix = 'has' . ( $ key -> isForMany ( ) ? 'Many' : 'One' ) ; $ methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});" ; } // if elseif ( $ key -> isForPivotTable ( ) ) { $ methodName = lcfirst ( $ key -> isForMany ( ) && $ key -> isForPivotTable ( ) ? $ relatedTable -> getName ( ) : $ relatedTable -> getModelName ( ) ) ; $ methodReturnSuffix = 'belongsToMany' ; $ methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel});" ; } // elseif else { $ methodName = lcfirst ( $ key -> isForMany ( ) && $ key -> isForPivotTable ( ) ? $ relatedTable -> getName ( ) : $ relatedTable -> getModelName ( ) ) ; $ methodReturnSuffix = 'belongsTo' ; $ methodContent = "return \$this->{$methodReturnSuffix}({$relatedModel}, '{$key->foreign}');" ; } // else $ methodName = preg_replace_callback ( '/(_[a-z])/' , function ( $ matches ) { return strtoupper ( substr ( $ matches [ 0 ] , 1 ) ) ; } , $ methodName ) ; $ method = "\t/**\n\t * Getter for {$relatedTable->getName()}.\n\t " . "* @return \\Illuminate\\Database\\Eloquent\\Relations\\" . ucfirst ( $ methodReturnSuffix ) . " \n\t */\n\t" . "public function {$methodName}()\n\t{\n\t\t{$methodContent}\n\t}" ; $ methods [ ] = $ method ; } // foreach } // if return array_unique ( $ methods ) ; }
Returns the parsed method calls for the foreign keys.
@return array
Returns the parsed method calls for the foreign keys .