src/CrudGeneratorCommands.php
public function createmodel($table) {
        $this->console->line("Preparing model attributes");
        $bar = $this->console->output->createProgressBar(4);
        $options = $this->console->options('path');
        //$modelName = $singular = substr($table, 0, strlen($table) - 1);
        $modelName = $singular = str_singular($table);
        if ($options['path'] != "") {
            $path = $options['path'];
        } else {
            $path = "app/" . ucfirst($modelName);
        }
        $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path));
        $AuxclassName = explode("/", str_replace(".php", "", $path));
        $className = "";
        $justPath = "";
        $prefijoPath = "/";
        $prefijo = "";
        $fileName = "";
        $nameSpace = "";
        foreach ($AuxclassName as $indice => $pedazo) {
            if ($indice == count($AuxclassName) - 1) {
                $nameSpace = $className;
                $fileName = str_finish(ucfirst($pedazo), ".php");
                $modelName = strtolower($pedazo);
            } else {
                $justPath .=$prefijoPath . $pedazo;
                $prefijoPath = "/";
            }
            $className .= $prefijo . ucfirst($pedazo);
            $prefijo = "\\";
        }
        $path = str_finish($path, ".php");
        $bar->advance();
        $this->console->line("Loading details from {$table} table");
        $config = CrudGenerator::getModelDetailsFromDb($table);
        $config["modelo"] = $config["model"] = $modelName;
        $config["nameSpace"] = $nameSpace;
        $bar->advance();
        $this->console->info("Details loaded!");
        //$this->console->line(print_r($config, true));
        $bar->advance();
        $confirm = $this->console->choice("Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?", ['yes', 'no'], 0);
        if ($confirm == 'yes') {
            $this->console->line("Saving Model for {$modelName} in {$path} with className '{$className}'");
            if (CrudGenerator::saveResource("sirgrimorum::templates.model", false, base_path($justPath), $fileName, $config)) {
                $this->console->info("Model file saved!");
                $bar->finish();
            } else {
                $this->console->error("Something went wrong and the model file could not be saved");
                $bar->finish();
            }
        } else {
            $bar->finish();
        }
    }
public function createmodel($table) {
        $this->console->line("Preparing model attributes");
        $bar = $this->console->output->createProgressBar(4);
        $options = $this->console->options('path');
        //$modelName = $singular = substr($table, 0, strlen($table) - 1);
        $modelName = $singular = str_singular($table);
        if ($options['path'] != "") {
            $path = $options['path'];
        } else {
            $path = "app/" . ucfirst($modelName);
        }
        $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path));
        $AuxclassName = explode("/", str_replace(".php", "", $path));
        $className = "";
        $justPath = "";
        $prefijoPath = "/";
        $prefijo = "";
        $fileName = "";
        $nameSpace = "";
        foreach ($AuxclassName as $indice => $pedazo) {
            if ($indice == count($AuxclassName) - 1) {
                $nameSpace = $className;
                $fileName = str_finish(ucfirst($pedazo), ".php");
                $modelName = strtolower($pedazo);
            } else {
                $justPath .=$prefijoPath . $pedazo;
                $prefijoPath = "/";
            }
            $className .= $prefijo . ucfirst($pedazo);
            $prefijo = "\\";
        }
        $path = str_finish($path, ".php");
        $bar->advance();
        $this->console->line("Loading details from {$table} table");
        $config = CrudGenerator::getModelDetailsFromDb($table);
        $config["modelo"] = $config["model"] = $modelName;
        $config["nameSpace"] = $nameSpace;
        $bar->advance();
        $this->console->info("Details loaded!");
        //$this->console->line(print_r($config, true));
        $bar->advance();
        $confirm = $this->console->choice("Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?", ['yes', 'no'], 0);
        if ($confirm == 'yes') {
            $this->console->line("Saving Model for {$modelName} in {$path} with className '{$className}'");
            if (CrudGenerator::saveResource("sirgrimorum::templates.model", false, base_path($justPath), $fileName, $config)) {
                $this->console->info("Model file saved!");
                $bar->finish();
            } else {
                $this->console->error("Something went wrong and the model file could not be saved");
                $bar->finish();
            }
        } else {
            $bar->finish();
        }
    }
public function createmodel ( $ table ) { $ this -> console -> line ( "Preparing model attributes" ) ; $ bar = $ this -> console -> output -> createProgressBar ( 4 ) ; $ options = $ this -> console -> options ( 'path' ) ; //$modelName = $singular = substr($table, 0, strlen($table) - 1); $ modelName = $ singular = str_singular ( $ table ) ; if ( $ options [ 'path' ] != "" ) { $ path = $ options [ 'path' ] ; } else { $ path = "app/" . ucfirst ( $ modelName ) ; } $ path = str_replace ( "//" , "/" , str_replace ( [ "\\" , " " ] , [ "/" , "" ] , $ path ) ) ; $ AuxclassName = explode ( "/" , str_replace ( ".php" , "" , $ path ) ) ; $ className = "" ; $ justPath = "" ; $ prefijoPath = "/" ; $ prefijo = "" ; $ fileName = "" ; $ nameSpace = "" ; foreach ( $ AuxclassName as $ indice => $ pedazo ) { if ( $ indice == count ( $ AuxclassName ) - 1 ) { $ nameSpace = $ className ; $ fileName = str_finish ( ucfirst ( $ pedazo ) , ".php" ) ; $ modelName = strtolower ( $ pedazo ) ; } else { $ justPath .= $ prefijoPath . $ pedazo ; $ prefijoPath = "/" ; } $ className .= $ prefijo . ucfirst ( $ pedazo ) ; $ prefijo = "\\" ; } $ path = str_finish ( $ path , ".php" ) ; $ bar -> advance ( ) ; $ this -> console -> line ( "Loading details from {$table} table" ) ; $ config = CrudGenerator :: getModelDetailsFromDb ( $ table ) ; $ config [ "modelo" ] = $ config [ "model" ] = $ modelName ; $ config [ "nameSpace" ] = $ nameSpace ; $ bar -> advance ( ) ; $ this -> console -> info ( "Details loaded!" ) ; //$this->console->line(print_r($config, true)); $ bar -> advance ( ) ; $ confirm = $ this -> console -> choice ( "Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?" , [ 'yes' , 'no' ] , 0 ) ; if ( $ confirm == 'yes' ) { $ this -> console -> line ( "Saving Model for {$modelName} in {$path} with className '{$className}'" ) ; if ( CrudGenerator :: saveResource ( "sirgrimorum::templates.model" , false , base_path ( $ justPath ) , $ fileName , $ config ) ) { $ this -> console -> info ( "Model file saved!" ) ; $ bar -> finish ( ) ; } else { $ this -> console -> error ( "Something went wrong and the model file could not be saved" ) ; $ bar -> finish ( ) ; } } else { $ bar -> finish ( ) ; } }
Create a Model file based on a database table
@param string $table Table name
Create a Model file based on a database table