示例#1
0
 /**
  * Funcao para buscar e montar o sistema de relacionamentos do Eloquent
  * 
  * @param string $table Nome da tabela que sera gerada
  * @return string Funcao gerada
  */
 public function _getRelations($table)
 {
     $this->var_config_relations = [];
     $stubModelConfig = $this->files->get(__DIR__ . '/stubs/model_function_relation.stub');
     // Pega os relacionamentos no banco
     $AppLogic = new Logic\AppLogic();
     $relations = $AppLogic->buildRelationships($table);
     // dd($relations);
     $field_types = $AppLogic->_getFieldTypes();
     if ($relations) {
         $stubs = [];
         foreach ($relations as $rel) {
             // Copia a stub mae
             $stub_child = trim(substr(trim($stubModelConfig), 5)) . "\n\n";
             // Tentativa fim
             // Trampo pra pegar a primeira coluna para o possivel nome do campo
             $columns = $AppLogic->buildColumns($rel->table_primary, $rel->schema_primary);
             $field_name = $columns[0]->name;
             foreach ($columns as $column) {
                 if ($field_types[$column->type] == 'string') {
                     $field_name = $column->name;
                     break;
                 }
             }
             // Setta as configuracoes
             $arrConfig = array('relation_class_name' => $AppLogic->controllerName($rel->table_primary), 'relation_field_id' => $rel->table_foreign_field, 'relation_field_fkey' => $rel->table_primary_field, 'relation_field_name' => $field_name);
             // Tentativa de automatizar o processo, na criacao da var_config
             $this->var_config_relations[$rel->table_foreign_field] = $arrConfig;
             // Traduz a stub
             Logic\UtilLogic::translateStub($arrConfig, $stub_child);
             $stubs[] = $stub_child;
         }
         return implode("\n\n", $stubs);
     } else {
         return '';
     }
 }
示例#2
0
 /**
  * Funcao para buscar e montar o sistema de relacionamentos do Eloquent
  * 
  * @param string $table Nome da tabela que sera gerada
  * @return void
  */
 private function _getRelations($table)
 {
     $this->var_config_relations = [];
     // Pega os relacionamentos no banco
     $AppLogic = new Logic\AppLogic();
     $relations = $AppLogic->buildRelationships($table);
     // dd($relations);
     $field_types = $AppLogic->_getFieldTypes();
     if ($relations) {
         $stubs = [];
         foreach ($relations as $rel) {
             // Trampo pra pegar a primeira coluna para o possivel nome do campo
             $columns = $AppLogic->buildColumns($rel->table_primary, $rel->schema_primary);
             $field_name = $columns[0]->name;
             foreach ($columns as $column) {
                 if ($field_types[$column->type] == 'string') {
                     $field_name = $column->name;
                     break;
                 }
             }
             // Setta as configuracoes
             $arrConfig = array('relation_class_name' => $AppLogic->controllerName($rel->table_primary), 'relation_field_id' => $rel->table_foreign_field, 'relation_field_fkey' => $rel->table_primary_field, 'relation_field_name' => $field_name);
             // Tentativa de automatizar o processo, na criacao da var_config
             $this->var_config_relations[$rel->table_foreign_field] = $arrConfig;
         }
     }
 }