mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2025-01-27 20:37:55 +03:00
bug fixed: soft deletes missing in the model
This commit is contained in:
parent
5ad49aa58a
commit
8e57d36894
16
README.md
16
README.md
@ -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:
|
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:
|
`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`.
|
- **--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:
|
- **--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**
|
- **Seeder and Test generators**
|
||||||
|
|
||||||
- Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
|
- 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**
|
- **Version 1.3.1**
|
||||||
|
|
||||||
|
1917
composer.lock
generated
1917
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,5 @@
|
|||||||
<?php
|
<?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) {
|
$app->get("/", function () use ($app) {
|
||||||
return $app->welcome();
|
return $app->welcome();
|
||||||
});
|
});
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
<?php
|
<?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) {
|
$factory->define(App\User::class, function ($faker) {
|
||||||
return [
|
return [
|
||||||
'name' => $faker->name,
|
'name' => $faker->name,
|
||||||
@ -19,3 +8,4 @@ $factory->define(App\User::class, function ($faker) {
|
|||||||
'remember_token' => str_random(10),
|
'remember_token' => str_random(10),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -106,3 +106,29 @@ $I->seeInThisFile(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$I->deleteFile('./tests/tmp/TestingModel.php');
|
$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');
|
||||||
|
@ -14,6 +14,7 @@ class ModelCommand extends BaseCommand {
|
|||||||
{--rules= : fields validation rules.}
|
{--rules= : fields validation rules.}
|
||||||
{--timestamps=true : enables timestamps on the model.}
|
{--timestamps=true : enables timestamps on the model.}
|
||||||
{--path=app : where to store the model php file.}
|
{--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}
|
{--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}
|
{--force= : override the existing files}
|
||||||
';
|
';
|
||||||
@ -33,7 +34,8 @@ class ModelCommand extends BaseCommand {
|
|||||||
'dates' => $this->getAsArrayFields('dates'),
|
'dates' => $this->getAsArrayFields('dates'),
|
||||||
'relations' => $this->getRelations(),
|
'relations' => $this->getRelations(),
|
||||||
'rules' => $this->getRules(),
|
'rules' => $this->getRules(),
|
||||||
'additional' => $this->getAdditional()
|
'additional' => $this->getAdditional(),
|
||||||
|
'uses' => $this->getUses()
|
||||||
])
|
])
|
||||||
->get();
|
->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
|
||||||
|
: '';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ class ResourceCommand extends BaseCommand {
|
|||||||
'--path' => $this->option('path'),
|
'--path' => $this->option('path'),
|
||||||
'--force' => $this->option('force'),
|
'--force' => $this->option('force'),
|
||||||
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
|
'--timestamps' => $this->hasTimestamps() ? 'true' : 'false',
|
||||||
|
'--soft-deletes' => $this->hasSoftDeletes() ? 'true' : 'false',
|
||||||
'--parsed' => true
|
'--parsed' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -191,4 +192,10 @@ class ResourceCommand extends BaseCommand {
|
|||||||
|| in_array('timestampsTz', $additionals);
|
|| in_array('timestampsTz', $additionals);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function hasSoftDeletes()
|
||||||
|
{
|
||||||
|
$additionals = explode(',', $this->option('add'));
|
||||||
|
return in_array('softDeletes', $additionals);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
|
|
||||||
class {{name}} extends Model {
|
class {{name}} extends Model {
|
||||||
|
|
||||||
protected $fillable = [{{fillable}}];
|
{{uses}} protected $fillable = [{{fillable}}];
|
||||||
|
|
||||||
protected $dates = [{{dates}}];
|
protected $dates = [{{dates}}];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user