예제 #1
0
 /**
  * Saves the model content for a table.
  * @param TableMigration $table
  * @return MakeMWBModel
  */
 protected function saveModelForTable(TableMigration $table)
 {
     $dates = [];
     $fields = $table->getFields();
     $modelContent = (new ModelContent('\\' . $this->getAppNamespace() . $table->getModelName()))->setTable($table->getName());
     if (array_key_exists($field = 'deleted_at', $fields)) {
         unset($fields[$field]);
         $dates[] = $field;
         $modelContent->setTraits(['\\Illuminate\\Database\\Eloquent\\SoftDeletes']);
     }
     // if
     if (array_key_exists($field = 'created_at', $fields)) {
         unset($fields[$field]);
         $dates[] = $field;
     }
     // if
     if (array_key_exists($field = 'updated_at', $fields)) {
         unset($fields[$field]);
         $dates[] = $field;
     }
     // if
     if ($dates) {
         $modelContent->setDates($dates);
     }
     // if
     unset($fields['id']);
     $modelContent->setFillable(array_diff(array_keys($fields), $table->getBlacklist()));
     $modelContent->setCasts($table->getCastedFields());
     if ($genericCalls = $table->getGenericCalls()) {
         foreach ($genericCalls as $call) {
             if ($call instanceof ForeignKey) {
                 $modelContent->addForeignKey($call);
             }
             // if
         }
         // foreach
     }
     // if
     if ($sources = $table->getRelationSources()) {
         foreach ($sources as $call) {
             if ($call instanceof ForeignKey) {
                 $modelContent->addForeignKey($call);
             }
             // if
         }
         // foreach
     }
     // if
     $modelContent->save();
     return $this;
 }
예제 #2
0
 /**
  * Generates the model and migration for/with laravel and extends the contents of the generated classes.
  * @param \DOMNode $node The node of the table.
  * @return MakeMWBModel|bool False if the table should be ignored.
  */
 protected function loadModelTable(\DOMNode $node)
 {
     $tableObject = new TableMigration($this);
     $loaded = $tableObject->load($node);
     if ($loaded && in_array($tableObject->getName(), $this->pivotTables)) {
         $tableObject->isPivotTable(true);
     } else {
         if ($tableObject->isPivotTable()) {
             $this->pivotTables[] = $tableObject->getName();
         }
     }
     // else if
     return $loaded ? $tableObject : false;
 }