private function generateRelations() { if ($this->commandData->tableName == '') { return ''; } $code = ''; //Get what tables it belongs to $relations = DataBaseHelper::getForeignKeysFromTable($this->commandData->tableName); foreach ($relations as $r) { $referencedTableName = preg_replace("/{$this->prefix}/uis", '', $r->REFERENCED_TABLE_NAME); $referencedTableName = ucfirst(Str::camel(StringUtils::singularize($referencedTableName))); $code .= " public function " . $referencedTableName . "() {\n"; $code .= " " . 'return $this->belongsTo(' . "'\$NAMESPACE_MODEL\$\\" . $referencedTableName . "', '" . $r->COLUMN_NAME . "'); \n"; $code .= " }\n\n"; } //Get what tables it is referenced $relations = DataBaseHelper::getReferencesFromTable($this->commandData->tableName); foreach ($relations as $r) { $tableName = preg_replace("/{$this->prefix}/uis", '', $r->TABLE_NAME); $tableName = ucfirst(Str::camel(StringUtils::singularize($tableName))); $code .= " public function " . Str::plural($tableName) . "() {\n"; $code .= " " . 'return $this->hasMany(' . "'\$NAMESPACE_MODEL\$\\" . $tableName . "', '" . $r->COLUMN_NAME . "'); \n"; $code .= " }\n\n"; } return $code; }
private function generateRelations() { if ($this->commandData->tableName == '') { return ''; } $code = ''; //Get what tables it belongs to $relations = DataBaseHelper::getForeignKeysFromTable($this->commandData->tableName); foreach ($relations as $r) { $code .= "\tpublic function " . StringUtils::singularize($r->REFERENCED_TABLE_NAME) . "() {\n"; $code .= "\t\t" . 'return $this->belongsTo(' . "\$NAMESPACE_MODEL\$\\" . ucfirst(Str::camel(StringUtils::singularize($r->REFERENCED_TABLE_NAME))) . "::class, '" . $r->COLUMN_NAME . "'); \n"; $code .= "\t}\n\n"; } //Get what tables it is referended $relations = DataBaseHelper::getReferencesFromTable($this->commandData->tableName); foreach ($relations as $r) { $code .= "\tpublic function " . Str::plural($r->TABLE_NAME) . "() {\n"; $code .= "\t\t" . 'return $this->hasMany(' . "\$NAMESPACE_MODEL\$\\" . ucfirst(Str::camel(StringUtils::singularize($r->TABLE_NAME))) . "::class, '" . $r->COLUMN_NAME . "'); \n"; $code .= "\t}\n\n"; } return $code; }