diff --git a/doc/options.md b/doc/options.md index 21c5069..b2ced3e 100644 --- a/doc/options.md +++ b/doc/options.md @@ -20,7 +20,7 @@ | `--form-helper` | Helper for the form. eg. `--form-helper=html`, `--form-helper=laravelcollective` | | `--localize` | Allow to localize. e.g. localize=yes | | `--locales` | Locales language type. e.g. locals=en | -| `--soft-deletes` | Include soft deletes fields | +| `--soft-deletes` | Include soft deletes fields. eg. `--soft-deletes=yes` | ### Controller Options: @@ -59,7 +59,7 @@ | `--fillable` | The name of the view path | | `--relationships` | The relationships for the model. e.g. `--relationships="comments#hasMany#App\Comment"` in the format | | `--pk` | The name of the primary key | -| `--soft-deletes` | Include soft deletes fields | +| `--soft-deletes` | Include soft deletes fields. eg. `--soft-deletes=yes` | ### Migration Options: @@ -69,7 +69,7 @@ | `--indexes` | The fields to add an index to. append "#unique" to a field name to add a unique index. Create composite fields by separating fieldnames with a pipe (` --indexes="title,field1|field2#unique" ` will create normal index on title, and unique composite on fld1 and fld2) | | `--foreign-keys` | Any foreign keys for the table. e.g. `--foreign-keys="user_id#id#users#cascade"` where user_id is the column name, id is the name of the field on the foreign table, users is the name of the foreign table, and cascade is the operation 'ON DELETE' together with 'ON UPDATE' | | `--pk` | The name of the primary key | -| `--soft-deletes` | Include soft deletes fields | +| `--soft-deletes` | Include soft deletes fields. eg. `--soft-deletes=yes` | ### Lang Options: @@ -94,6 +94,7 @@ | `--relationships` | The relationships for the model. e.g. `--relationships="comments#hasMany#App\Comment"` in the format | | `--route` | Include Crud route to routes.php? yes or no | | `--route-group` | Prefix of the route group | +| `--soft-deletes` | Include soft deletes fields. eg. `--soft-deletes=yes` | ### API Controller Options: diff --git a/src/Commands/CrudApiCommand.php b/src/Commands/CrudApiCommand.php index 7833db3..6cf5488 100644 --- a/src/Commands/CrudApiCommand.php +++ b/src/Commands/CrudApiCommand.php @@ -25,7 +25,8 @@ class CrudApiCommand extends Command {--foreign-keys= : The foreign keys for the table.} {--relationships= : The relationships for the model.} {--route=yes : Include Crud route to routes.php? yes|no.} - {--route-group= : Prefix of the route group.}'; + {--route-group= : Prefix of the route group.} + {--soft-deletes=no : Include soft deletes fields.}'; /** * The console command description. @@ -105,9 +106,11 @@ public function handle() $validations = $this->processJSONValidations($this->option('fields_from_file')); } + $softDeletes = $this->option('soft-deletes'); + $this->call('crud:api-controller', ['name' => $controllerNamespace . $name . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--pagination' => $perPage, '--validations' => $validations]); - $this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships]); - $this->call('crud:migration', ['name' => $migrationName, '--schema' => $fields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys]); + $this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $softDeletes]); + $this->call('crud:migration', ['name' => $migrationName, '--schema' => $fields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]); // For optimizing the class loader $this->callSilent('optimize'); diff --git a/src/Commands/CrudCommand.php b/src/Commands/CrudCommand.php index b201907..8df6841 100644 --- a/src/Commands/CrudCommand.php +++ b/src/Commands/CrudCommand.php @@ -30,7 +30,7 @@ class CrudCommand extends Command {--form-helper=html : Helper for generating the form.} {--localize=no : Allow to localize? yes|no.} {--locales=en : Locales language type.} - {--soft-deletes : Include soft deletes fields.}'; + {--soft-deletes=no : Include soft deletes fields.}'; /** * The console command description. @@ -123,10 +123,11 @@ public function handle() } $formHelper = $this->option('form-helper'); + $softDeletes = $this->option('soft-deletes'); $this->call('crud:controller', ['name' => $controllerNamespace . $name . 'Controller', '--crud-name' => $name, '--model-name' => $modelName, '--model-namespace' => $modelNamespace, '--view-path' => $viewPath, '--route-group' => $routeGroup, '--pagination' => $perPage, '--fields' => $fields, '--validations' => $validations]); - $this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $this->option('soft-deletes')]); - $this->call('crud:migration', ['name' => $migrationName, '--schema' => $migrationFields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $this->option('soft-deletes')]); + $this->call('crud:model', ['name' => $modelNamespace . $modelName, '--fillable' => $fillable, '--table' => $tableName, '--pk' => $primaryKey, '--relationships' => $relationships, '--soft-deletes' => $softDeletes]); + $this->call('crud:migration', ['name' => $migrationName, '--schema' => $migrationFields, '--pk' => $primaryKey, '--indexes' => $indexes, '--foreign-keys' => $foreignKeys, '--soft-deletes' => $softDeletes]); $this->call('crud:view', ['name' => $name, '--fields' => $fields, '--validations' => $validations, '--view-path' => $viewPath, '--route-group' => $routeGroup, '--localize' => $localize, '--pk' => $primaryKey, '--form-helper' => $formHelper]); if ($localize == 'yes') { $this->call('crud:lang', ['name' => $name, '--fields' => $fields, '--locales' => $locales]); diff --git a/src/Commands/CrudMigrationCommand.php b/src/Commands/CrudMigrationCommand.php index dbf86f5..68989b4 100644 --- a/src/Commands/CrudMigrationCommand.php +++ b/src/Commands/CrudMigrationCommand.php @@ -17,7 +17,7 @@ class CrudMigrationCommand extends GeneratorCommand {--indexes= : The fields to add an index to.} {--foreign-keys= : Foreign keys.} {--pk=id : The name of the primary key.} - {--soft-deletes : Include soft deletes fields.}'; + {--soft-deletes=no : Include soft deletes fields.}'; /** * The console command description. @@ -209,17 +209,18 @@ protected function buildClass($name) } $primaryKey = $this->option('pk'); + $softDeletes = $this->option('soft-deletes'); - $softDeletes = ''; - if ($this->option('soft-deletes')) { - $softDeletes = "\$table->softDeletes();\n" . $tabIndent . $tabIndent . $tabIndent; + $softDeletesSnippets = ''; + if ($softDeletes == 'yes') { + $softDeletesSnippets = "\$table->softDeletes();\n" . $tabIndent . $tabIndent . $tabIndent; } $schemaUp = "Schema::create('" . $tableName . "', function (Blueprint \$table) { \$table->increments('" . $primaryKey . "'); \$table->timestamps();\n" . $tabIndent . $tabIndent . $tabIndent . - $softDeletes . + $softDeletesSnippets . $schemaFields . "});"; diff --git a/src/Commands/CrudModelCommand.php b/src/Commands/CrudModelCommand.php index b084622..1fa6504 100644 --- a/src/Commands/CrudModelCommand.php +++ b/src/Commands/CrudModelCommand.php @@ -17,7 +17,7 @@ class CrudModelCommand extends GeneratorCommand {--fillable= : The names of the fillable columns.} {--relationships= : The relationships for the model} {--pk=id : The name of the primary key.} - {--soft-deletes : Include soft deletes fields.}'; + {--soft-deletes=no : Include soft deletes fields.}'; /** * The console command description. @@ -71,6 +71,7 @@ protected function buildClass($name) $fillable = $this->option('fillable'); $primaryKey = $this->option('pk'); $relationships = trim($this->option('relationships')) != '' ? explode(',', trim($this->option('relationships'))) : []; + $softDeletes = $this->option('soft-deletes'); if (!empty($primaryKey)) { $primaryKey = <<replaceTable($stub, $table) ->replaceFillable($stub, $fillable) ->replacePrimaryKey($stub, $primaryKey) - ->replaceSoftDelete($stub, $this->option('soft-deletes')); + ->replaceSoftDelete($stub, $softDeletes); foreach ($relationships as $rel) { // relationshipname#relationshiptype#args_separated_by_pipes @@ -169,13 +170,13 @@ protected function replacePrimaryKey(&$stub, $primaryKey) * Replace the (optional) soft deletes part for the given stub. * * @param string $stub - * @param boolean $replaceSoftDelete + * @param string $replaceSoftDelete * * @return $this */ - protected function replaceSoftDelete(&$stub, $replaceSoftDelete = false) + protected function replaceSoftDelete(&$stub, $replaceSoftDelete) { - if ($replaceSoftDelete) { + if ($replaceSoftDelete == 'yes') { $stub = str_replace('{{softDeletes}}', "use SoftDeletes;\n ", $stub); $stub = str_replace('{{useSoftDeletes}}', "use Illuminate\Database\Eloquent\SoftDeletes;\n", $stub); } else {