|
|
|
@ -9,6 +9,9 @@ use Illuminate\Filesystem\Filesystem; |
|
|
|
class CrudMake extends Command |
|
|
|
{ |
|
|
|
private $files; |
|
|
|
private $modelName; |
|
|
|
private $pluralModelName; |
|
|
|
private $lowerCasePluralModel; |
|
|
|
|
|
|
|
public function __construct(Filesystem $files) |
|
|
|
{ |
|
|
|
@ -38,48 +41,54 @@ class CrudMake extends Command |
|
|
|
*/ |
|
|
|
public function fire() |
|
|
|
{ |
|
|
|
$model = $this->argument('name'); |
|
|
|
$pluralModel = str_plural($model); |
|
|
|
$lowerCasePluralModel = strtolower($pluralModel); |
|
|
|
$this->getModelName(); |
|
|
|
|
|
|
|
$this->generateModel($model); |
|
|
|
$this->generateController($pluralModel); |
|
|
|
$this->generateMigration($model, $lowerCasePluralModel); |
|
|
|
$this->generateViews($model, $lowerCasePluralModel); |
|
|
|
$this->generateTests($model, $pluralModel); |
|
|
|
$this->generateModel(); |
|
|
|
$this->generateController(); |
|
|
|
$this->generateMigration(); |
|
|
|
$this->generateViews(); |
|
|
|
$this->generateTests(); |
|
|
|
|
|
|
|
$this->info('CRUD files generated successfully!'); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateModel($model) |
|
|
|
public function getModelName() |
|
|
|
{ |
|
|
|
$this->callSilent('make:model', ['name' => $model]);; |
|
|
|
$this->modelName = $this->argument('name'); |
|
|
|
|
|
|
|
$this->info($model.' model generated.'); |
|
|
|
$this->pluralModelName = str_plural($this->modelName); |
|
|
|
$this->lowerCasePluralModel = strtolower($this->pluralModelName); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateController($pluralModelName) |
|
|
|
public function generateModel() |
|
|
|
{ |
|
|
|
$this->callSilent('make:model', ['name' => $this->modelName]);; |
|
|
|
|
|
|
|
$this->info($this->modelName.' model generated.'); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateController() |
|
|
|
{ |
|
|
|
if (! $this->files->isDirectory(app_path('Http/Controllers'))) { |
|
|
|
$this->files->makeDirectory(app_path('Http/Controllers'), 0777, true, true); |
|
|
|
} |
|
|
|
|
|
|
|
$controllerPath = app_path('Http/Controllers/'.$pluralModelName.'Controller.php'); |
|
|
|
$controllerPath = app_path('Http/Controllers/'.$this->pluralModelName.'Controller.php'); |
|
|
|
$this->files->put($controllerPath, $this->files->get(__DIR__.'/stubs/controller.model.stub')); |
|
|
|
|
|
|
|
$this->info($pluralModelName.'Controller generated.'); |
|
|
|
$this->info($this->pluralModelName.'Controller generated.'); |
|
|
|
} |
|
|
|
public function generateMigration($model, $lowerCasePluralModel) |
|
|
|
public function generateMigration() |
|
|
|
{ |
|
|
|
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$lowerCasePluralModel.'_table.php'); |
|
|
|
$migrationFilePath = database_path('migrations/'.date('Y_m_d_His').'_create_'.$this->lowerCasePluralModel.'_table.php'); |
|
|
|
$this->files->put($migrationFilePath, $this->files->get(__DIR__.'/stubs/migration-create.stub')); |
|
|
|
|
|
|
|
$this->info($model.' table migration generated.'); |
|
|
|
$this->info($this->modelName.' table migration generated.'); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateViews($model, $lowerCasePluralModel) |
|
|
|
public function generateViews() |
|
|
|
{ |
|
|
|
$viewPath = resource_path('views/'.$lowerCasePluralModel); |
|
|
|
$viewPath = resource_path('views/'.$this->lowerCasePluralModel); |
|
|
|
if (! $this->files->isDirectory($viewPath)) { |
|
|
|
$this->files->makeDirectory($viewPath, 0777, true, true); |
|
|
|
} |
|
|
|
@ -87,15 +96,15 @@ class CrudMake extends Command |
|
|
|
$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->info($this->modelName.' view files generated.'); |
|
|
|
} |
|
|
|
|
|
|
|
public function generateTests($model, $pluralModelName) |
|
|
|
public function generateTests() |
|
|
|
{ |
|
|
|
$this->callSilent('make:test', ['name' => 'Manage'.$pluralModelName.'Test']); |
|
|
|
$this->info('Manage'.$pluralModelName.'Test generated.'); |
|
|
|
$this->callSilent('make:test', ['name' => 'Manage'.$this->pluralModelName.'Test']); |
|
|
|
$this->info('Manage'.$this->pluralModelName.'Test generated.'); |
|
|
|
|
|
|
|
$this->callSilent('make:test', ['name' => 'Models/'.$model.'Test', '--unit' => true]); |
|
|
|
$this->info($model.'Test (model) generated.'); |
|
|
|
$this->callSilent('make:test', ['name' => 'Models/'.$this->modelName.'Test', '--unit' => true]); |
|
|
|
$this->info($this->modelName.'Test (model) generated.'); |
|
|
|
} |
|
|
|
} |