Browse Source

Added migration file generator

tags/0.1.0
Nafies Luthfi 8 years ago
parent
commit
0020a19a31
  1. 16
      src/CrudMake.php
  2. 33
      src/stubs/migration-create.stub
  3. 5
      tests/CrudMakeCommandTest.php

16
src/CrudMake.php

@ -42,19 +42,23 @@ class CrudMake extends Command
$pluralModel = str_plural($model);
$lowerCasePluralModel = strtolower($pluralModel);
$this->callSilent('make:model', ['name' => $model]);
$this->info($model.' model generated.');
$this->callSilent('make:controller', ['name' => $pluralModel.'Controller']);
$this->info($pluralModel.'Controller generated.');
$path = resource_path('views/'.$lowerCasePluralModel);
if (! $this->files->isDirectory($path)) {
$this->files->makeDirectory($path, 0777, true, true);
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$lowerCasePluralModel.'_table.php');
$this->files->put($migrationFilePath, $this->files->get(__DIR__.'/stubs/migration-create.stub'));
$this->info($model.' table migration generated.');
$viewPath = resource_path('views/'.$lowerCasePluralModel);
if (! $this->files->isDirectory($viewPath)) {
$this->files->makeDirectory($viewPath, 0777, true, true);
}
$this->files->put($path.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub'));
$this->files->put($path.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub'));
$this->files->put($viewPath.'/index.blade.php', $this->files->get(__DIR__.'/stubs/view-index.stub'));
$this->files->put($viewPath.'/forms.blade.php', $this->files->get(__DIR__.'/stubs/view-forms.stub'));
$this->info($model.' view files generated.');
$this->callSilent('make:test', ['name' => 'Manage'.$pluralModel.'Test']);
$this->info('Manage'.$pluralModel.'Test generated.');

33
src/stubs/migration-create.stub

@ -0,0 +1,33 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class DummyClass extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('DummyTable', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 60);
$table->string('description');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('DummyTable');
}
}

5
tests/CrudMakeCommandTest.php

@ -16,6 +16,10 @@ class CrudMakeCommandTest extends TestCase
$this->assertFileExists(app_path('Test.php'));
$this->assertFileExists(app_path('Http/Controllers/TestsController.php'));
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_tests_table.php');
$this->assertFileExists($migrationFilePath);
$this->assertFileExists(resource_path('views/tests/index.blade.php'));
$this->assertFileExists(resource_path('views/tests/forms.blade.php'));
$this->assertFileExists(base_path('tests/Feature/ManageTestsTest.php'));
@ -23,6 +27,7 @@ class CrudMakeCommandTest extends TestCase
exec('rm '.app_path('Test.php'));
exec('rm -r '.app_path('Http'));
exec('rm '.$migrationFilePath);
exec('rm -r '.resource_path('views/tests'));
exec('rm -r '.base_path('tests/Feature'));
exec('rm -r '.base_path('tests/Unit'));

Loading…
Cancel
Save