bug fixed: soft deletes missing in the model

This commit is contained in:
Amine Ben hammou 2017-01-28 14:35:11 +00:00
parent 5ad49aa58a
commit 8e57d36894
8 changed files with 266 additions and 1736 deletions

View File

@ -259,10 +259,10 @@ More then that, you can generate multiple resources with only one command ! [Cli
The `wn:model` command is used to generate a model class based on Eloquent. It has the following syntax:
```
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--force=true]
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--timestamps=false] [--path=...] [--soft-deletes=true] [--force=true]
```
- **name**: the name of the model.
- **name**: the name of the model.
`php artisan wn:model Task` generates the following:
@ -361,6 +361,8 @@ gives:
- **--timestamps**: Enables timestamps on the model. Giving `--timestamps=false` will add `public $timestamps = false;` to the generated model. The default value is `true`.
- **--soft-deletes**: Adds `Illuminate\Database\Eloquent\SoftDeletes` trait to the model. This is disabled by default.
- **--force**: tells the generator to override the existing file. By default, if the model file already exists, it will not be overriden and the output will be something like:
```
@ -638,6 +640,16 @@ To test the generators, I included a fresh lumen installation under the folder `
- **Seeder and Test generators**
- Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
- Requested Feature: [Fractal integration](https://github.com/webNeat/lumen-generators/issues/24)
- Requested Feature: [Add possibility to not run migrations when using `wn:resources`](https://github.com/webNeat/lumen-generators/issues/23)
- Documentation: [Adding examples](https://github.com/webNeat/lumen-generators/issues/20)
- **Version 1.3.2**
- Bug Fixed: [softDeletes not added to model](https://github.com/webNeat/lumen-generators/issues/25)
- **Version 1.3.1**

1917
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,16 +1,5 @@
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app->get("/", function () use ($app) {
return $app->welcome();
});

View File

@ -1,16 +1,5 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
$factory->define(App\User::class, function ($faker) {
return [
'name' => $faker->name,
@ -19,3 +8,4 @@ $factory->define(App\User::class, function ($faker) {
'remember_token' => str_random(10),
];
});

View File

@ -106,3 +106,29 @@ $I->seeInThisFile(
);
$I->deleteFile('./tests/tmp/TestingModel.php');
$I->wantTo('generate a model with softDeletes');
$I->runShellCommand('php artisan wn:model TestingModel --soft-deletes=true --path=tests/tmp --force=true');
$I->seeFileFound('./tests/tmp/TestingModel.php');
$I->openFile('./tests/tmp/TestingModel.php');
$I->seeFileContentsEqual('<?php namespace Tests\Tmp;
use Illuminate\Database\Eloquent\Model;
class TestingModel extends Model {
use Illuminate\Database\Eloquent\SoftDeletes;
protected $fillable = [];
protected $dates = [];
public static $rules = [
// Validation rules
];
// Relationships
}
');
$I->deleteFile('./tests/tmp/TestingModel.php');

View File

@ -14,6 +14,7 @@ class ModelCommand extends BaseCommand {
{--rules= : fields validation rules.}
{--timestamps=true : enables timestamps on the model.}
{--path=app : where to store the model php file.}
{--soft-deletes= : adds SoftDeletes trait to the model.}
{--parsed : tells the command that arguments have been already parsed. To use when calling the command from an other command and passing the parsed arguments and options}
{--force= : override the existing files}
';
@ -33,7 +34,8 @@ class ModelCommand extends BaseCommand {
'dates' => $this->getAsArrayFields('dates'),
'relations' => $this->getRelations(),
'rules' => $this->getRules(),
'additional' => $this->getAdditional()
'additional' => $this->getAdditional(),
'uses' => $this->getUses()
])
->get();
@ -123,4 +125,11 @@ class ModelCommand extends BaseCommand {
: '';
}
protected function getUses()
{
return $this->option('soft-deletes') == 'true'
? ' use Illuminate\Database\Eloquent\SoftDeletes;' . PHP_EOL . PHP_EOL
: '';
}
}

View File

@ -42,6 +42,7 @@ class ResourceCommand extends BaseCommand {
'--path' => $this->option('path'),
'--force' => $this->option('force'),
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
'--parsed' => true
]);
@ -191,4 +192,10 @@ class ResourceCommand extends BaseCommand {
|| in_array('timestampsTz', $additionals);
}
protected function hasSoftDeletes()
{
$additionals = explode(',', $this->option('add'));
return in_array('softDeletes', $additionals);
}
}

View File

@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model;
class {{name}} extends Model {
protected $fillable = [{{fillable}}];
{{uses}} protected $fillable = [{{fillable}}];
protected $dates = [{{dates}}];