app/Console/Commands/Support/Model/CreateModel.php
/**
     * Esegui il console command.
     *
     * @return mixed
     */
Esegui il console command.
@return mixed
Esegui il console command . @return mixed
public function handle(): void
    {
        $table = $this->argument('table');
        $this->model = ucfirst($this->argument('model'));
        $this->translatable = ($this->option('translatable') == 'true');
        $this->sluggable = ($this->option('sluggable') == 'true');
        if ($this->model === '' && !$this->isGuessedModelCorrect($table))
            return;
        $schemaBuilder = DB::getSchemaBuilder();
        echo "Reading [$table] table" . PHP_EOL;
        foreach ($schemaBuilder->getColumnListing($table) as $column) {
            $type = $schemaBuilder->getColumnType($table, $column);
            $col = $schemaBuilder->getConnection()->getDoctrineColumn($table, $column);
            $not_null = (int)$col->getNotNull();
            echo "Column name: [$column] => [$type], required => [$not_null]" . PHP_EOL;
            $this->fields[$column] = [
                'type'         => $type,
                'translatable' => $this->isTranslatable($column),
                'relation'     => $this->isRelation($column),
                'not_null'     => $not_null 
            ];
        }
        $this->setTranslatable();
        $this->setSluggable();
        $this->setFillable();
        $this->setFieldSpec();
        $this->dropLines();
        $this->writeModel();
    }
public function handle ( ) : void { $ table = $ this -> argument ( 'table' ) ; $ this -> model = ucfirst ( $ this -> argument ( 'model' ) ) ; $ this -> translatable = ( $ this -> option ( 'translatable' ) == 'true' ) ; $ this -> sluggable = ( $ this -> option ( 'sluggable' ) == 'true' ) ; if ( $ this -> model === '' && ! $ this -> isGuessedModelCorrect ( $ table ) ) return ; $ schemaBuilder = DB :: getSchemaBuilder ( ) ; echo " Reading [ $ table ] table " . PHP_EOL ; foreach ( $ schemaBuilder -> getColumnListing ( $ table ) as $ column ) { $ type = $ schemaBuilder -> getColumnType ( $ table , $ column ) ; $ col = $ schemaBuilder -> getConnection ( ) -> getDoctrineColumn ( $ table , $ column ) ; $ not_null = ( int ) $ col -> getNotNull ( ) ; echo " Column name: [ $ column ] => [ $ type ], required => [ $ not_null ] " . PHP_EOL ; $ this -> fields [ $ column ] = [ 'type' => $ type , 'translatable' => $ this -> isTranslatable ( $ column ) , 'relation' => $ this -> isRelation ( $ column ) , 'not_null' => $ not_null ] ; } $ this -> setTranslatable ( ) ; $ this -> setSluggable ( ) ; $ this -> setFillable ( ) ; $ this -> setFieldSpec ( ) ; $ this -> dropLines ( ) ; $ this -> writeModel ( ) ; }
Esegui il console command.
Esegui il console command .
// Se non viene fornito un nome per il Model tenta di ipotizzarne uno in automatico. // Instance Doctrine SchemaBuilder. // Loop table columns. // not null value must be required // Compile the nodel staub. // Rimuovi le righe inutili. // Scrivi il Model.