Browse Source

Add migration generator class

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
da5a25536d
  1. 32
      src/CrudMake.php
  2. 34
      src/Generators/MigrationGenerator.php
  3. 2
      src/Generators/ModelGenerator.php

32
src/CrudMake.php

@ -5,6 +5,7 @@ namespace Luthfi\CrudGenerator;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Luthfi\CrudGenerator\Generators\ControllerGenerator;
use Luthfi\CrudGenerator\Generators\MigrationGenerator;
use Luthfi\CrudGenerator\Generators\ModelGenerator;
class CrudMake extends Command
@ -79,7 +80,7 @@ class CrudMake extends Command
$this->generateResourceRoute();
app(ModelGenerator::class, ['command' => $this])->generate();
$this->generateMigration();
app(MigrationGenerator::class, ['command' => $this])->generate();
app(ControllerGenerator::class, ['command' => $this])->generate();
$this->generateViews();
$this->generateLangFile();
@ -143,24 +144,6 @@ class CrudMake extends Command
}
/**
* Generate migration file for the model
*
* @return void
*/
public function generateMigration()
{
$prefix = date('Y_m_d_His');
$tableName = $this->modelNames['table_name'];
$migrationPath = $this->makeDirectory(database_path('migrations'));
$migrationFilePath = $migrationPath.'/'.$prefix."_create_{$tableName}_table.php";
$this->generateFile($migrationFilePath, $this->getMigrationContent());
$this->info($this->modelNames['model_name'].' table migration generated.');
}
/**
* Generate the index view and forms view files
*
* @return void
@ -281,17 +264,6 @@ class CrudMake extends Command
}
/**
* Get migration file content from migration stub
*
* @return string Replaced proper model names in migration file content
*/
private function getMigrationContent()
{
$stub = $this->files->get(__DIR__.'/stubs/migration-create.stub');
return $this->replaceStubString($stub);
}
/**
* Get index view file content from index view stub
*
* @return string Replaced proper model names in view file content

34
src/Generators/MigrationGenerator.php

@ -0,0 +1,34 @@
<?php
namespace Luthfi\CrudGenerator\Generators;
/**
* Migration Generator Class
*/
class MigrationGenerator extends BaseGenerator
{
/**
* {@inheritDoc}
*/
public function generate()
{
$prefix = date('Y_m_d_His');
$tableName = $this->modelNames['table_name'];
$migrationPath = $this->makeDirectory(database_path('migrations'));
$migrationFilePath = $migrationPath.'/'.$prefix."_create_{$tableName}_table.php";
$this->generateFile($migrationFilePath, $this->getContent());
$this->command->info($this->modelNames['model_name'].' table migration generated.');
}
/**
* {@inheritDoc}
*/
protected function getContent()
{
$stub = $this->files->get(__DIR__.'/../stubs/migration-create.stub');
return $this->replaceStubString($stub);
}
}

2
src/Generators/ModelGenerator.php

@ -3,7 +3,7 @@
namespace Luthfi\CrudGenerator\Generators;
/**
* Controller Generator Class
* Model Generator Class
*/
class ModelGenerator extends BaseGenerator
{

Loading…
Cancel
Save