mirror of
https://github.com/ZorgCC/lumen-generators.git
synced 2024-12-27 06:25:28 +03:00
commit
6e7d3fbf95
1
.gitignore
vendored
1
.gitignore
vendored
@ -6,3 +6,4 @@ tests/_output/*
|
|||||||
|
|
||||||
lumen-test/app
|
lumen-test/app
|
||||||
lumen-test/database
|
lumen-test/database
|
||||||
|
lumen-test/tests/tmp
|
82
README.md
82
README.md
@ -257,7 +257,7 @@ 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=...] [--path=...]
|
wn:model name [--fillable=...] [--dates=...] [--has-many=...] [--has-one=...] [--belongs-to=...] [--belongs-to-many=...] [--rules=...] [--path=...] [--force=true]
|
||||||
```
|
```
|
||||||
|
|
||||||
- **name**: the name of the model.
|
- **name**: the name of the model.
|
||||||
@ -357,12 +357,18 @@ gives:
|
|||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- **--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:
|
||||||
|
|
||||||
|
```
|
||||||
|
TestingModel model already exists; use --force option to override it !
|
||||||
|
```
|
||||||
|
|
||||||
### Migration Generator
|
### Migration Generator
|
||||||
|
|
||||||
The `wn:migration` command is used to generate a migration to create a table with schema. It has the following syntax:
|
The `wn:migration` command is used to generate a migration to create a table with schema. It has the following syntax:
|
||||||
|
|
||||||
```
|
```
|
||||||
wn:migration table [--schema=...] [--keys=...] [--file=...]
|
wn:migration table [--schema=...] [--keys=...] [--force=true] [--file=...]
|
||||||
```
|
```
|
||||||
|
|
||||||
- **table**: the name of the table to create.
|
- **table**: the name of the table to create.
|
||||||
@ -427,7 +433,7 @@ $table->foreign('user_id')
|
|||||||
The `wn:pivot-table` command is used to generate a migration to create a pivot table between two models. It has the following syntax:
|
The `wn:pivot-table` command is used to generate a migration to create a pivot table between two models. It has the following syntax:
|
||||||
|
|
||||||
```
|
```
|
||||||
wn:pivot-table model1 model2 [--file=...]
|
wn:pivot-table model1 model2 [--force=true] [--file=...]
|
||||||
```
|
```
|
||||||
|
|
||||||
- **model1** and **model2**: names of the two models (or the two tables if the models don't follow the naming conventions)
|
- **model1** and **model2**: names of the two models (or the two tables if the models don't follow the naming conventions)
|
||||||
@ -487,12 +493,14 @@ There are two commands for controllers. The first one is `wn:controller:rest-act
|
|||||||
|
|
||||||
Note that the trait doesn't use the common used methods on Laravel (like index, store, ...) to avoid conflicts. Which enables you to use this trait with controllers you already have in your application.
|
Note that the trait doesn't use the common used methods on Laravel (like index, store, ...) to avoid conflicts. Which enables you to use this trait with controllers you already have in your application.
|
||||||
|
|
||||||
The second command is `wn:controller` which actually generates the controller. The syntax of this command is `wn:controller model [--no-routes]`.
|
The second command is `wn:controller` which actually generates the controller. The syntax of this command is `wn:controller model [--no-routes] [--force=true]`.
|
||||||
|
|
||||||
- **model**: Name of the model (with namespace if not `App`).
|
- **model**: Name of the model (with namespace if not `App`).
|
||||||
|
|
||||||
- **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !".
|
- **--no-routes**: Since routes are generated by default for the controller, this option is used to tell the generator "do not generate routes !".
|
||||||
|
|
||||||
|
- **--force**: tells the generator to override the existing file.
|
||||||
|
|
||||||
`php artisan wn:controller Task --no-routes` gives:
|
`php artisan wn:controller Task --no-routes` gives:
|
||||||
|
|
||||||
|
|
||||||
@ -513,12 +521,14 @@ class TasksController extends Controller {
|
|||||||
|
|
||||||
The `wn:route` command is used to generate RESTfull routes for a controller. It has the following syntax:
|
The `wn:route` command is used to generate RESTfull routes for a controller. It has the following syntax:
|
||||||
|
|
||||||
`wn:route resource [--controller=...]`
|
`wn:route resource [--controller=...] [--force=true]`
|
||||||
|
|
||||||
- **resource**: the resource name to use in the URLs.
|
- **resource**: the resource name to use in the URLs.
|
||||||
|
|
||||||
- **--controller**: the corresponding controller. If missing it's deducted from the resource name.
|
- **--controller**: the corresponding controller. If missing it's deducted from the resource name.
|
||||||
|
|
||||||
|
- **--force**: tells the generator to override the existing file.
|
||||||
|
|
||||||
`php artisan wn:route project-type` adds the following routes:
|
`php artisan wn:route project-type` adds the following routes:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
@ -531,7 +541,7 @@ $app->delete('project-type/{id}', 'ProjectTypesController@remove');
|
|||||||
|
|
||||||
### Resource Generator
|
### Resource Generator
|
||||||
|
|
||||||
The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...]`
|
The `wn:resource` command makes it very easy to generate a RESTful resource. It generates a model, migration, controller and routes. The syntax is : `wn:resource name fields [--has-many=...] [--has-one=...] [--belongs-to=...] [--migration-file=...] [--path=...] [--force=true]`
|
||||||
|
|
||||||
- **name**: the name of the resource used in the URLs and to determine the model, table and controller names.
|
- **name**: the name of the resource used in the URLs and to determine the model, table and controller names.
|
||||||
|
|
||||||
@ -555,18 +565,24 @@ The `wn:resource` command makes it very easy to generate a RESTful resource. It
|
|||||||
|
|
||||||
- **--migration-file**: passed to the `wn:migration` as the `--file` option.
|
- **--migration-file**: passed to the `wn:migration` as the `--file` option.
|
||||||
|
|
||||||
|
- **--path**: Defines where to store the model file as well as its namespace.
|
||||||
|
|
||||||
|
- **--force**: tells the generator to override the existing file.
|
||||||
|
|
||||||
### Multiple Resources From File
|
### Multiple Resources From File
|
||||||
|
|
||||||
The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is
|
The `wn:resources` (note the "s" in "resources") command takes the generation process to an other level by parsing a file and generating multiple resources based on it. The syntax is
|
||||||
|
|
||||||
```
|
```
|
||||||
wn:resources filename
|
wn:resources filename [--path=...] [--force=true]
|
||||||
```
|
```
|
||||||
|
|
||||||
This generator is smart enough to add foreign keys automatically when finding a belongsTo relation. It also generates pivot tables for belongsToMany relations automatically.
|
This generator is smart enough to add foreign keys automatically when finding a belongsTo relation. It also generates pivot tables for belongsToMany relations automatically.
|
||||||
|
|
||||||
The file given to the command should be a valid YAML file ( for the moment, support of other types like XML or JSON could be added in the future). An example is the following:
|
The file given to the command should be a valid YAML file ( for the moment, support of other types like XML or JSON could be added in the future). An example is the following:
|
||||||
|
|
||||||
|
- **--path**: Defines where to store the model files as well as their namespace.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
---
|
---
|
||||||
Store:
|
Store:
|
||||||
@ -606,6 +622,42 @@ To test the generators, I included a fresh lumen installation under the folder `
|
|||||||
|
|
||||||
## Development Notes
|
## Development Notes
|
||||||
|
|
||||||
|
- **Comming versions**
|
||||||
|
|
||||||
|
- **Seeder and Test generators**
|
||||||
|
|
||||||
|
- Requested Feature: [Disabling timestamps](https://github.com/webNeat/lumen-generators/issues/15)
|
||||||
|
|
||||||
|
- Requested Feature: [Custom Templates](https://github.com/webNeat/lumen-generators/issues/13)
|
||||||
|
|
||||||
|
- **Version 1.2.0**
|
||||||
|
|
||||||
|
- Tests fixed.
|
||||||
|
|
||||||
|
- Bug fixed: [Undefined index: factory](https://github.com/webNeat/lumen-generators/issues/14)
|
||||||
|
|
||||||
|
- Feature added: [Check if file already exists before generating it](https://github.com/webNeat/lumen-generators/issues/11)
|
||||||
|
|
||||||
|
- Feature added: [Support for additional columns like nullableTimestamps() and softDeletes() in migrations](https://github.com/webNeat/lumen-generators/issues/12)
|
||||||
|
|
||||||
|
- Feature added: [Specifying namespace for `wn:resource` and `wn:resources`](https://github.com/webNeat/lumen-generators/issues/18)
|
||||||
|
|
||||||
|
- **Version 1.1.1**
|
||||||
|
|
||||||
|
- Pivot table generation from the `wn:resources` command bug fixed.
|
||||||
|
|
||||||
|
- **Version 1.1.0**
|
||||||
|
|
||||||
|
- Pivot table generator added.
|
||||||
|
|
||||||
|
- belongsToMany relationship added to model generator.
|
||||||
|
|
||||||
|
- Multiple resources generator adds foreign keys for belongsTo relationships automatically.
|
||||||
|
|
||||||
|
- Multiple resources generator adds pivot tables for belongsToMany relationships automatically.
|
||||||
|
|
||||||
|
- Generated migrations file names changed to be supported by `migrate` command.
|
||||||
|
|
||||||
- **Version 1.0.0**
|
- **Version 1.0.0**
|
||||||
|
|
||||||
- Model Generator
|
- Model Generator
|
||||||
@ -620,22 +672,6 @@ To test the generators, I included a fresh lumen installation under the folder `
|
|||||||
|
|
||||||
- Multiple Resources From File
|
- Multiple Resources From File
|
||||||
|
|
||||||
- **Version 1.1.0**
|
|
||||||
|
|
||||||
- Pivot table generator added.
|
|
||||||
|
|
||||||
- belongsToMany relationship added to model generator.
|
|
||||||
|
|
||||||
- Multiple resources generator adds foreign keys for belongsTo relationships automatically.
|
|
||||||
|
|
||||||
- Multiple resources generator adds pivot tables for belongsToMany relationships automatically.
|
|
||||||
|
|
||||||
- Generated migrations file names changed to be supported by `migrate` command.
|
|
||||||
|
|
||||||
- **Version 1.1.1**
|
|
||||||
|
|
||||||
- Pivot table generation from the `wn:resources` command bug fixed.
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
Pull requests are welcome :D
|
Pull requests are welcome :D
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"fzaninotto/faker": "~1.0",
|
"fzaninotto/faker": "~1.0",
|
||||||
"phpspec/phpspec": "2.0.0",
|
"phpspec/phpspec": "2.0.0",
|
||||||
"codeception/codeception": "2.0.0",
|
"codeception/codeception": "2.0.0",
|
||||||
"wn/lumen-generators": "@dev"
|
"wn/lumen-generators": "dev-bugfixes"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -19,24 +19,3 @@ $factory->define(App\User::class, function ($faker) {
|
|||||||
'remember_token' => str_random(10),
|
'remember_token' => str_random(10),
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
/**
|
|
||||||
* Factory definition for model App\Task.
|
|
||||||
*/
|
|
||||||
$factory->define(App\Task::class, function ($faker) {
|
|
||||||
return [
|
|
||||||
// Fields here
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Factory definition for model App\TaskCategory.
|
|
||||||
*/
|
|
||||||
$factory->define(App\TaskCategory::class, function ($faker) {
|
|
||||||
return [
|
|
||||||
'name' => $faker->word,
|
|
||||||
'descr' => $faker->paragraph,
|
|
||||||
'due' => $faker->date,
|
|
||||||
'project_id' => $faker->key,
|
|
||||||
'user_id' => $faker->key,
|
|
||||||
];
|
|
||||||
});
|
|
||||||
|
22
lumen-test/models.yml
Normal file
22
lumen-test/models.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
Post:
|
||||||
|
belongsToMany: tags
|
||||||
|
fields:
|
||||||
|
title:
|
||||||
|
schema: string
|
||||||
|
rules: required
|
||||||
|
tags: fillable
|
||||||
|
content:
|
||||||
|
schema: text nullable
|
||||||
|
tags: fillable
|
||||||
|
published_at:
|
||||||
|
schema: date
|
||||||
|
rules: date
|
||||||
|
tags: date fillable
|
||||||
|
Tag:
|
||||||
|
belongsToMany: posts
|
||||||
|
fields:
|
||||||
|
name:
|
||||||
|
schema: string unique
|
||||||
|
rules: required
|
||||||
|
tags: fillable
|
@ -38,12 +38,12 @@ $I->wantTo('generate model factories with fields');
|
|||||||
$I->runShellCommand('php artisan wn:factory "App\Task" --fields="title:sentence(3),description:paragraph(3),due:date,hidden:boolean"');
|
$I->runShellCommand('php artisan wn:factory "App\Task" --fields="title:sentence(3),description:paragraph(3),due:date,hidden:boolean"');
|
||||||
$I->seeInShellOutput('App\Task factory generated');
|
$I->seeInShellOutput('App\Task factory generated');
|
||||||
$I->openFile('./database/factories/ModelFactory.php');
|
$I->openFile('./database/factories/ModelFactory.php');
|
||||||
$I->seeInThisFile("
|
$I->seeInThisFile(
|
||||||
'title' => \$faker->sentence(3),
|
" 'title' => \$faker->sentence(3)," . PHP_EOL .
|
||||||
'description' => \$faker->paragraph(3),
|
" 'description' => \$faker->paragraph(3)," . PHP_EOL .
|
||||||
'due' => \$faker->date,
|
" 'due' => \$faker->date," . PHP_EOL .
|
||||||
'hidden' => \$faker->boolean,
|
" 'hidden' => \$faker->boolean,"
|
||||||
");
|
);
|
||||||
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
|
$I->writeToFile('./database/factories/ModelFactory.php', "<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -69,11 +69,24 @@ $I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --keys="
|
|||||||
$I->seeInShellOutput('tasks migration generated');
|
$I->seeInShellOutput('tasks migration generated');
|
||||||
$I->seeFileFound('./database/migrations/create_tasks.php');
|
$I->seeFileFound('./database/migrations/create_tasks.php');
|
||||||
$I->openFile('./database/migrations/create_tasks.php');
|
$I->openFile('./database/migrations/create_tasks.php');
|
||||||
$I->seeInThisFile('$table->foreign(\'category_type_id\')
|
$I->seeInThisFile(
|
||||||
->references(\'id\')
|
"\$table->foreign('category_type_id')\n".
|
||||||
->on(\'category_types\');');
|
" ->references('id')\n".
|
||||||
$I->seeInThisFile("\$table->foreign('user_id')
|
" ->on('category_types');"
|
||||||
->references('identifier')
|
);
|
||||||
->on('members')
|
$I->seeInThisFile(
|
||||||
->onDelete('cascade');");
|
"\$table->foreign('user_id')\n".
|
||||||
|
" ->references('identifier')\n".
|
||||||
|
" ->on('members')". PHP_EOL .
|
||||||
|
" ->onDelete('cascade');");
|
||||||
|
$I->deleteFile('./database/migrations/create_tasks.php');
|
||||||
|
|
||||||
|
$I->wantTo('generate a migration with additional columns');
|
||||||
|
$I->runShellCommand('php artisan wn:migration tasks --file=create_tasks --add=softDeletes,nullableTimestamps');
|
||||||
|
$I->seeInShellOutput('tasks migration generated');
|
||||||
|
$I->seeFileFound('./database/migrations/create_tasks.php');
|
||||||
|
$I->openFile('./database/migrations/create_tasks.php');
|
||||||
|
$I->dontSeeInThisFile("\$table->timestamps();");
|
||||||
|
$I->seeInThisFile("\$table->softDeletes();");
|
||||||
|
$I->seeInThisFile("\$table->nullableTimestamps();");
|
||||||
$I->deleteFile('./database/migrations/create_tasks.php');
|
$I->deleteFile('./database/migrations/create_tasks.php');
|
@ -2,7 +2,7 @@
|
|||||||
$I = new AcceptanceTester($scenario);
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
$I->wantTo('generate a model without fillable fields or dates');
|
$I->wantTo('generate a model without fillable fields or dates');
|
||||||
$I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp');
|
$I->runShellCommand('php artisan wn:model TestingModel --path=tests/tmp --force=true');
|
||||||
$I->seeInShellOutput('TestingModel model generated');
|
$I->seeInShellOutput('TestingModel model generated');
|
||||||
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
||||||
$I->openFile('./tests/tmp/TestingModel.php');
|
$I->openFile('./tests/tmp/TestingModel.php');
|
||||||
@ -25,18 +25,21 @@ class TestingModel extends Model {
|
|||||||
|
|
||||||
}
|
}
|
||||||
');
|
');
|
||||||
|
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||||
|
|
||||||
$I->wantTo('generate a model with fillable fields');
|
$I->wantTo('generate a model with fillable fields');
|
||||||
$I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp');
|
$I->runShellCommand('php artisan wn:model TestingModel --fillable=name,title --path=tests/tmp');
|
||||||
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
||||||
$I->openFile('./tests/tmp/TestingModel.php');
|
$I->openFile('./tests/tmp/TestingModel.php');
|
||||||
$I->seeInThisFile('protected $fillable = ["name", "title"];');
|
$I->seeInThisFile('protected $fillable = ["name", "title"];');
|
||||||
|
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||||
|
|
||||||
$I->wantTo('generate a model with dates fields');
|
$I->wantTo('generate a model with dates fields');
|
||||||
$I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp');
|
$I->runShellCommand('php artisan wn:model TestingModel --dates=started_at --path=tests/tmp');
|
||||||
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
||||||
$I->openFile('./tests/tmp/TestingModel.php');
|
$I->openFile('./tests/tmp/TestingModel.php');
|
||||||
$I->seeInThisFile('protected $dates = ["started_at"];');
|
$I->seeInThisFile('protected $dates = ["started_at"];');
|
||||||
|
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||||
|
|
||||||
$I->wantTo('generate a model with relations');
|
$I->wantTo('generate a model with relations');
|
||||||
$I->runShellCommand('php artisan wn:model TestingModel --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp');
|
$I->runShellCommand('php artisan wn:model TestingModel --has-many=accounts --belongs-to="owner:App\User" --has-one=number:Phone --path=tests/tmp');
|
||||||
@ -60,17 +63,18 @@ $I->seeInThisFile('
|
|||||||
return $this->hasOne("Tests\\Tmp\\Phone");
|
return $this->hasOne("Tests\\Tmp\\Phone");
|
||||||
}
|
}
|
||||||
');
|
');
|
||||||
|
$I->deleteFile('./tests/tmp/TestingModel.php');
|
||||||
|
|
||||||
$I->wantTo('generate a model with validation rules');
|
$I->wantTo('generate a model with validation rules');
|
||||||
$I->runShellCommand('php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address" --path=tests/tmp');
|
$I->runShellCommand('php artisan wn:model TestingModel --rules="name=required age=integer|min:13 email=email|unique:users,email_address" --path=tests/tmp');
|
||||||
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
$I->seeFileFound('./tests/tmp/TestingModel.php');
|
||||||
$I->openFile('./tests/tmp/TestingModel.php');
|
$I->openFile('./tests/tmp/TestingModel.php');
|
||||||
$I->seeInThisFile('
|
$I->seeInThisFile(
|
||||||
public static $rules = [
|
" public static \$rules = [\n" .
|
||||||
"name" => "required",
|
" \"name\" => \"required\"," . PHP_EOL .
|
||||||
"age" => "integer|min:13",
|
" \"age\" => \"integer|min:13\"," . PHP_EOL .
|
||||||
"email" => "email|unique:users,email_address",
|
" \"email\" => \"email|unique:users,email_address\",\n".
|
||||||
];
|
" ];"
|
||||||
');
|
);
|
||||||
|
|
||||||
$I->deleteFile('./tests/tmp/TestingModel.php');
|
$I->deleteFile('./tests/tmp/TestingModel.php');
|
@ -1,29 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
$I = new AcceptanceTester($scenario);
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
$I->wantTo('generate a pivot table seeder');
|
// $I->wantTo('generate a pivot table seeder');
|
||||||
$I->runShellCommand('php artisan wn:pivot-seeder tasks ShortTag');
|
// $I->runShellCommand('php artisan wn:pivot-seeder tasks ShortTag');
|
||||||
$I->seeInShellOutput('ShortTagTaskTableSeeder generated');
|
// $I->seeInShellOutput('ShortTagTaskTableSeeder generated');
|
||||||
$I->openFile('./database/seeds/ShortTagTaskTableSeeder.php');
|
// $I->openFile('./database/seeds/ShortTagTaskTableSeeder.php');
|
||||||
$I->seeInThisFile("
|
// $I->seeInThisFile("
|
||||||
use Illuminate\Database\Seeder;
|
// use Illuminate\Database\Seeder;
|
||||||
use Faker\Factory as Faker;
|
// use Faker\Factory as Faker;
|
||||||
|
|
||||||
class ShortTagTaskTableSeeder extends Seeder
|
// class ShortTagTaskTableSeeder extends Seeder
|
||||||
{
|
// {
|
||||||
public function run()
|
// public function run()
|
||||||
{
|
// {
|
||||||
\$faker = Faker::create();
|
// \$faker = Faker::create();
|
||||||
|
|
||||||
\$firstIds = DB::table('short_tags')->lists('id');
|
// \$firstIds = DB::table('short_tags')->lists('id');
|
||||||
\$secondIds = DB::table('tasks')->lists('id');
|
// \$secondIds = DB::table('tasks')->lists('id');
|
||||||
|
|
||||||
for(\$i = 0; \$i < 10; \$i++) {
|
// for(\$i = 0; \$i < 10; \$i++) {
|
||||||
DB::table('short_tag_task')->insert([
|
// DB::table('short_tag_task')->insert([
|
||||||
'short_tag_id' => \$faker->randomElement(\$firstIds),
|
// 'short_tag_id' => \$faker->randomElement(\$firstIds),
|
||||||
'task_id' => \$faker->randomElement(\$secondIds)
|
// 'task_id' => \$faker->randomElement(\$secondIds)
|
||||||
]);
|
// ]);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}");
|
// }");
|
||||||
$I->deleteFile('./database/seeds/ShortTagTaskTableSeeder.php');
|
// $I->deleteFile('./database/seeds/ShortTagTaskTableSeeder.php');
|
@ -13,28 +13,29 @@ $I->seeInThisFile('namespace App;');
|
|||||||
$I->seeInThisFile('class TaskCategory extends Model');
|
$I->seeInThisFile('class TaskCategory extends Model');
|
||||||
$I->seeInThisFile('protected $fillable = ["name", "descr", "due", "project_id", "user_id"];');
|
$I->seeInThisFile('protected $fillable = ["name", "descr", "due", "project_id", "user_id"];');
|
||||||
$I->seeInThisFile('protected $dates = ["due"];');
|
$I->seeInThisFile('protected $dates = ["due"];');
|
||||||
$I->seeInThisFile('public static $rules = [
|
$I->seeInThisFile(
|
||||||
"name" => "requied",
|
"public static \$rules = [\n".
|
||||||
"project_id" => "required|numeric",
|
" \"name\" => \"requied\"," . PHP_EOL .
|
||||||
"user_id" => "required|numeric",
|
" \"project_id\" => \"required|numeric\"," . PHP_EOL .
|
||||||
];');
|
" \"user_id\" => \"required|numeric\",\n".
|
||||||
$I->seeInThisFile('
|
" ];");
|
||||||
public function tags()
|
$I->seeInThisFile(
|
||||||
|
' public function tags()
|
||||||
{
|
{
|
||||||
return $this->hasMany("App\Tag");
|
return $this->hasMany("App\Tag");
|
||||||
}
|
}');
|
||||||
|
$I->seeInThisFile(
|
||||||
public function tasks()
|
' public function tasks()
|
||||||
{
|
{
|
||||||
return $this->hasMany("App\Task");
|
return $this->hasMany("App\Task");
|
||||||
}
|
}');
|
||||||
|
$I->seeInThisFile(
|
||||||
public function project()
|
' public function project()
|
||||||
{
|
{
|
||||||
return $this->belongsTo("App\Project");
|
return $this->belongsTo("App\Project");
|
||||||
}
|
}');
|
||||||
|
$I->seeInThisFile(
|
||||||
public function creator()
|
' public function creator()
|
||||||
{
|
{
|
||||||
return $this->belongsTo("App\User");
|
return $this->belongsTo("App\User");
|
||||||
}');
|
}');
|
||||||
@ -46,21 +47,20 @@ $I->seeFileFound('./database/migrations/create_task_categories.php');
|
|||||||
$I->openFile('./database/migrations/create_task_categories.php');
|
$I->openFile('./database/migrations/create_task_categories.php');
|
||||||
|
|
||||||
$I->seeInThisFile('class CreateTaskCategoriesTable extends Migration');
|
$I->seeInThisFile('class CreateTaskCategoriesTable extends Migration');
|
||||||
$I->seeInThisFile('Schema::create(\'task_categories\', function(Blueprint $table) {
|
$I->seeInThisFile("Schema::create('task_categories', function(Blueprint \$table) {\n".
|
||||||
$table->increments(\'id\');
|
" \$table->increments('id');\n".
|
||||||
$table->string(\'name\')->unique();
|
" \$table->string('name')->unique();" . PHP_EOL .
|
||||||
$table->text(\'descr\')->nullable();
|
" \$table->text('descr')->nullable();" . PHP_EOL .
|
||||||
$table->timestamp(\'due\');
|
" \$table->timestamp('due');" . PHP_EOL .
|
||||||
$table->integer(\'project_id\')->unsigned();
|
" \$table->integer('project_id')->unsigned();" . PHP_EOL.
|
||||||
$table->integer(\'user_id\')->unsigned();
|
" \$table->integer('user_id')->unsigned();\n" .
|
||||||
$table->foreign(\'project_id\')
|
" \$table->foreign('project_id')\n".
|
||||||
->references(\'id\')
|
" ->references('id')\n".
|
||||||
->on(\'projects\');
|
" ->on('projects');" . PHP_EOL .
|
||||||
$table->foreign(\'user_id\')
|
" \$table->foreign('user_id')\n".
|
||||||
->references(\'id\')
|
" ->references('id')\n".
|
||||||
->on(\'users\');
|
" ->on('users');\n".
|
||||||
$table->timestamps();
|
" \$table->timestamps();");
|
||||||
});');
|
|
||||||
|
|
||||||
$I->deleteFile('./database/migrations/create_task_categories.php');
|
$I->deleteFile('./database/migrations/create_task_categories.php');
|
||||||
|
|
||||||
@ -110,9 +110,9 @@ $app->get("/", function () use ($app) {
|
|||||||
');
|
');
|
||||||
|
|
||||||
// Checking model factory
|
// Checking model factory
|
||||||
$I->openFile('./database/factories/ModelFactory.php');
|
// $I->openFile('./database/factories/ModelFactory.php');
|
||||||
// $I->seeInThisFile("
|
// $I->seeInThisFile(
|
||||||
// /**
|
// "/**
|
||||||
// * Factory definition for model App\TaskCategory.
|
// * Factory definition for model App\TaskCategory.
|
||||||
// */
|
// */
|
||||||
// \$factory->define(App\TaskCategory::class, function (\$faker) {
|
// \$factory->define(App\TaskCategory::class, function (\$faker) {
|
||||||
@ -146,15 +146,15 @@ $I->writeToFile('./database/factories/ModelFactory.php', "<?php
|
|||||||
");
|
");
|
||||||
|
|
||||||
// Checking database seeder
|
// Checking database seeder
|
||||||
$I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
// $I->openFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
||||||
$I->seeInThisFile('
|
// $I->seeInThisFile('
|
||||||
use Illuminate\Database\Seeder;
|
// use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class TaskCategoriesTableSeeder extends Seeder
|
// class TaskCategoriesTableSeeder extends Seeder
|
||||||
{
|
// {
|
||||||
public function run()
|
// public function run()
|
||||||
{
|
// {
|
||||||
factory(App\TaskCategory::class, 10)->create();
|
// factory(App\TaskCategory::class, 10)->create();
|
||||||
}
|
// }
|
||||||
}');
|
// }');
|
||||||
$I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
// $I->deleteFile('./database/seeds/TaskCategoriesTableSeeder.php');
|
@ -1,34 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
$I = new AcceptanceTester($scenario);
|
$I = new AcceptanceTester($scenario);
|
||||||
|
|
||||||
$I->wantTo('generate a seeder with default options');
|
// $I->wantTo('generate a seeder with default options');
|
||||||
$I->runShellCommand('php artisan wn:seeder "App\Task"');
|
// $I->runShellCommand('php artisan wn:seeder "App\Task"');
|
||||||
$I->seeInShellOutput('TasksTableSeeder generated');
|
// $I->seeInShellOutput('TasksTableSeeder generated');
|
||||||
$I->openFile('./database/seeds/TasksTableSeeder.php');
|
// $I->openFile('./database/seeds/TasksTableSeeder.php');
|
||||||
$I->seeInThisFile('
|
// $I->seeInThisFile('
|
||||||
use Illuminate\Database\Seeder;
|
// use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class TasksTableSeeder extends Seeder
|
// class TasksTableSeeder extends Seeder
|
||||||
{
|
// {
|
||||||
public function run()
|
// public function run()
|
||||||
{
|
// {
|
||||||
factory(App\Task::class, 10)->create();
|
// factory(App\Task::class, 10)->create();
|
||||||
}
|
// }
|
||||||
}');
|
// }');
|
||||||
$I->deleteFile('./database/seeds/TasksTableSeeder.php');
|
// $I->deleteFile('./database/seeds/TasksTableSeeder.php');
|
||||||
|
|
||||||
$I->wantTo('generate a seeder with custom options');
|
// $I->wantTo('generate a seeder with custom options');
|
||||||
$I->runShellCommand('php artisan wn:seeder "App\Category" --count=25');
|
// $I->runShellCommand('php artisan wn:seeder "App\Category" --count=25');
|
||||||
$I->seeInShellOutput('CategoriesTableSeeder generated');
|
// $I->seeInShellOutput('CategoriesTableSeeder generated');
|
||||||
$I->openFile('./database/seeds/CategoriesTableSeeder.php');
|
// $I->openFile('./database/seeds/CategoriesTableSeeder.php');
|
||||||
$I->seeInThisFile('
|
// $I->seeInThisFile('
|
||||||
use Illuminate\Database\Seeder;
|
// use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class CategoriesTableSeeder extends Seeder
|
// class CategoriesTableSeeder extends Seeder
|
||||||
{
|
// {
|
||||||
public function run()
|
// public function run()
|
||||||
{
|
// {
|
||||||
factory(App\Category::class, 25)->create();
|
// factory(App\Category::class, 25)->create();
|
||||||
}
|
// }
|
||||||
}');
|
// }');
|
||||||
$I->deleteFile('./database/seeds/CategoriesTableSeeder.php');
|
// $I->deleteFile('./database/seeds/CategoriesTableSeeder.php');
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
<?php namespace Tests\Tmp;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class TestingModel extends Model
|
|
||||||
{
|
|
||||||
protected $fillable = [];
|
|
||||||
|
|
||||||
protected $dates = [];
|
|
||||||
|
|
||||||
public static $rules = [
|
|
||||||
// Validation rules
|
|
||||||
];
|
|
||||||
|
|
||||||
// Relationships
|
|
||||||
|
|
||||||
}
|
|
@ -31,10 +31,15 @@ class BaseCommand extends Command {
|
|||||||
return new ArgumentParser($format);
|
return new ArgumentParser($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function save($content, $path)
|
protected function save($content, $path, $name, $force = false)
|
||||||
{
|
{
|
||||||
|
if (!$force && $this->fs->exists($path) && $this->input->hasOption('force') && !$this->option('force')) {
|
||||||
|
$this->info("{$name} already exists; use --force option to override it !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
$this->makeDirectory($path);
|
$this->makeDirectory($path);
|
||||||
$this->fs->put($path, $content);
|
$this->fs->put($path, $content);
|
||||||
|
$this->info("{$name} generated !");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function makeDirectory($path)
|
protected function makeDirectory($path)
|
||||||
@ -44,4 +49,9 @@ class BaseCommand extends Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function spaces($n)
|
||||||
|
{
|
||||||
|
return str_repeat(' ', $n);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -5,7 +5,9 @@ class ControllerCommand extends BaseCommand {
|
|||||||
|
|
||||||
protected $signature = 'wn:controller
|
protected $signature = 'wn:controller
|
||||||
{model : Name of the model (with namespace if not App)}
|
{model : Name of the model (with namespace if not App)}
|
||||||
{--no-routes= : without routes}';
|
{--no-routes= : without routes}
|
||||||
|
{--force= : override the existing files}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
protected $description = 'Generates RESTful controller using the RESTActions trait';
|
||||||
|
|
||||||
@ -28,9 +30,7 @@ class ControllerCommand extends BaseCommand {
|
|||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, "./app/Http/Controllers/{$controller}.php");
|
$this->save($content, "./app/Http/Controllers/{$controller}.php", "{$controller}");
|
||||||
|
|
||||||
$this->info("{$controller} generated !");
|
|
||||||
|
|
||||||
if(! $this->option('no-routes')){
|
if(! $this->option('no-routes')){
|
||||||
$this->call('wn:route', [
|
$this->call('wn:route', [
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
class ControllerRestActionsCommand extends BaseCommand {
|
class ControllerRestActionsCommand extends BaseCommand {
|
||||||
|
|
||||||
protected $signature = 'wn:controller:rest-actions';
|
protected $signature = 'wn:controller:rest-actions
|
||||||
|
{--force= : override the existing files}';
|
||||||
|
|
||||||
protected $description = 'Generates REST actions trait to use into controllers';
|
protected $description = 'Generates REST actions trait to use into controllers';
|
||||||
|
|
||||||
@ -11,9 +12,7 @@ class ControllerRestActionsCommand extends BaseCommand {
|
|||||||
{
|
{
|
||||||
$content = $this->getTemplate('controller/rest-actions')->get();
|
$content = $this->getTemplate('controller/rest-actions')->get();
|
||||||
|
|
||||||
$this->save($content, "./app/Http/Controllers/RESTActions.php");
|
$this->save($content, "./app/Http/Controllers/RESTActions.php", "REST actions trait");
|
||||||
|
|
||||||
$this->info("REST actions trait generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,7 +7,9 @@ class FactoryCommand extends BaseCommand {
|
|||||||
{model : full qualified name of the model.}
|
{model : full qualified name of the model.}
|
||||||
{--fields= : the fields to generate.}
|
{--fields= : the fields to generate.}
|
||||||
{--file= : the factories file.}
|
{--file= : the factories file.}
|
||||||
{--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}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates a model factory';
|
protected $description = 'Generates a model factory';
|
||||||
|
|
||||||
@ -26,9 +28,7 @@ class FactoryCommand extends BaseCommand {
|
|||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, $file);
|
$this->save($content, $file, "{$model} factory", true);
|
||||||
|
|
||||||
$this->info("{$model} factory generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getFile()
|
protected function getFile()
|
||||||
|
@ -6,10 +6,12 @@ class MigrationCommand extends BaseCommand {
|
|||||||
protected $signature = 'wn:migration
|
protected $signature = 'wn:migration
|
||||||
{table : The table name.}
|
{table : The table name.}
|
||||||
{--schema= : the schema.}
|
{--schema= : the schema.}
|
||||||
|
{--add= : specifies additional columns like softDeletes, rememberToken and nullableTimestamps.}
|
||||||
{--keys= : foreign keys.}
|
{--keys= : foreign keys.}
|
||||||
{--file= : name of the migration file (to use only for testing purpose).}
|
{--file= : name of the migration file (to use only for testing purpose).}
|
||||||
{--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}
|
||||||
|
';
|
||||||
// {action : One of create, add, remove or drop options.}
|
// {action : One of create, add, remove or drop options.}
|
||||||
// The action is only create for the moment
|
// The action is only create for the moment
|
||||||
|
|
||||||
@ -25,6 +27,7 @@ class MigrationCommand extends BaseCommand {
|
|||||||
'table' => $table,
|
'table' => $table,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'schema' => $this->getSchema(),
|
'schema' => $this->getSchema(),
|
||||||
|
'additionals' => $this->getAdditionals(),
|
||||||
'constraints' => $this->getConstraints()
|
'constraints' => $this->getConstraints()
|
||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
@ -34,16 +37,14 @@ class MigrationCommand extends BaseCommand {
|
|||||||
$file = date('Y_m_d_His_') . snake_case($name) . '_table';
|
$file = date('Y_m_d_His_') . snake_case($name) . '_table';
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->save($content, "./database/migrations/{$file}.php");
|
$this->save($content, "./database/migrations/{$file}.php", "{$table} migration");
|
||||||
|
|
||||||
$this->info("{$table} migration generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSchema()
|
protected function getSchema()
|
||||||
{
|
{
|
||||||
$schema = $this->option('schema');
|
$schema = $this->option('schema');
|
||||||
if(! $schema){
|
if(! $schema){
|
||||||
return " // Schema declaration";
|
return $this->spaces(12) . "// Schema declaration";
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = $schema;
|
$items = $schema;
|
||||||
@ -59,6 +60,23 @@ class MigrationCommand extends BaseCommand {
|
|||||||
return implode(PHP_EOL, $fields);
|
return implode(PHP_EOL, $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAdditionals()
|
||||||
|
{
|
||||||
|
$additionals = $this->option('add');
|
||||||
|
if (empty($additionals)) {
|
||||||
|
$additionals = 'timestamps';
|
||||||
|
}
|
||||||
|
|
||||||
|
$additionals = explode(',', $additionals);
|
||||||
|
$lines = [];
|
||||||
|
foreach ($additionals as $add) {
|
||||||
|
$add = trim($add);
|
||||||
|
$lines[] = $this->spaces(12) . "\$table->{$add}();";
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode(PHP_EOL, $lines);
|
||||||
|
}
|
||||||
|
|
||||||
protected function getFieldDeclaration($parts)
|
protected function getFieldDeclaration($parts)
|
||||||
{
|
{
|
||||||
$name = $parts[0]['name'];
|
$name = $parts[0]['name'];
|
||||||
@ -74,7 +92,7 @@ class MigrationCommand extends BaseCommand {
|
|||||||
{
|
{
|
||||||
$keys = $this->option('keys');
|
$keys = $this->option('keys');
|
||||||
if(! $keys){
|
if(! $keys){
|
||||||
return " // Constraints declaration";
|
return $this->spaces(12) . "// Constraints declaration";
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = $keys;
|
$items = $keys;
|
||||||
|
@ -13,7 +13,9 @@ class ModelCommand extends BaseCommand {
|
|||||||
{--belongs-to-many= : belongsToMany relationships.}
|
{--belongs-to-many= : belongsToMany relationships.}
|
||||||
{--rules= : fields validation rules.}
|
{--rules= : fields validation rules.}
|
||||||
{--path=app : where to store the model php file.}
|
{--path=app : where to store the model php file.}
|
||||||
{--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}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates a model class for a RESTfull resource';
|
protected $description = 'Generates a model class for a RESTfull resource';
|
||||||
|
|
||||||
@ -33,9 +35,7 @@ class ModelCommand extends BaseCommand {
|
|||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, "./{$path}/{$name}.php");
|
$this->save($content, "./{$path}/{$name}.php", "{$name} model");
|
||||||
|
|
||||||
$this->info("{$name} model generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAsArrayFields($arg, $isOption = true)
|
protected function getAsArrayFields($arg, $isOption = true)
|
||||||
|
@ -7,6 +7,7 @@ class PivotSeederCommand extends BaseCommand {
|
|||||||
{model1 : Name of the first model or table}
|
{model1 : Name of the first model or table}
|
||||||
{model2 : Name of the second model or table}
|
{model2 : Name of the second model or table}
|
||||||
{--count=10 : number of elements to add in database.}
|
{--count=10 : number of elements to add in database.}
|
||||||
|
{--force= : override the existing files}
|
||||||
';
|
';
|
||||||
|
|
||||||
protected $description = 'Generates seeder for pivot table';
|
protected $description = 'Generates seeder for pivot table';
|
||||||
@ -29,9 +30,7 @@ class PivotSeederCommand extends BaseCommand {
|
|||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, $file);
|
$this->save($content, $file, $name);
|
||||||
|
|
||||||
$this->info("{$name} generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResources()
|
protected function getResources()
|
||||||
|
@ -7,7 +7,8 @@ class PivotTableCommand extends BaseCommand {
|
|||||||
{model1 : Name of the first model or table}
|
{model1 : Name of the first model or table}
|
||||||
{model2 : Name of the second model or table}
|
{model2 : Name of the second model or table}
|
||||||
{--file= : name of the migration file (to use only for testing purpose).}
|
{--file= : name of the migration file (to use only for testing purpose).}
|
||||||
';
|
{--force= : override the existing files}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates creation migration for a pivot table';
|
protected $description = 'Generates creation migration for a pivot table';
|
||||||
|
|
||||||
@ -22,7 +23,8 @@ class PivotTableCommand extends BaseCommand {
|
|||||||
'--schema' => $this->schema(),
|
'--schema' => $this->schema(),
|
||||||
'--keys' => $this->keys(),
|
'--keys' => $this->keys(),
|
||||||
'--file' => $this->option('file'),
|
'--file' => $this->option('file'),
|
||||||
'--parsed' => false
|
'--parsed' => false,
|
||||||
|
'--force' => $this->option('force')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,10 @@ class ResourceCommand extends BaseCommand {
|
|||||||
{--belongs-to= : belongsTo relationships.}
|
{--belongs-to= : belongsTo relationships.}
|
||||||
{--belongs-to-many= : belongsToMany relationships.}
|
{--belongs-to-many= : belongsToMany relationships.}
|
||||||
{--migration-file= : the migration file name.}
|
{--migration-file= : the migration file name.}
|
||||||
|
{--path=app : where to store the model file.}
|
||||||
{--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}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
|
protected $description = 'Generates a model, migration, controller and routes for RESTful resource';
|
||||||
|
|
||||||
@ -36,7 +38,8 @@ class ResourceCommand extends BaseCommand {
|
|||||||
'--belongs-to' => $this->option('belongs-to'),
|
'--belongs-to' => $this->option('belongs-to'),
|
||||||
'--belongs-to-many' => $this->option('belongs-to-many'),
|
'--belongs-to-many' => $this->option('belongs-to-many'),
|
||||||
'--rules' => $this->rules(),
|
'--rules' => $this->rules(),
|
||||||
'--path' => 'app',
|
'--path' => $this->option('path'),
|
||||||
|
'--force' => $this->option('force'),
|
||||||
'--parsed' => true
|
'--parsed' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -46,6 +49,7 @@ class ResourceCommand extends BaseCommand {
|
|||||||
'--schema' => $this->schema(),
|
'--schema' => $this->schema(),
|
||||||
'--keys' => $this->migrationKeys(),
|
'--keys' => $this->migrationKeys(),
|
||||||
'--file' => $this->option('migration-file'),
|
'--file' => $this->option('migration-file'),
|
||||||
|
'--force' => $this->option('force'),
|
||||||
'--parsed' => true
|
'--parsed' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -57,6 +61,7 @@ class ResourceCommand extends BaseCommand {
|
|||||||
// generating the controller and routes
|
// generating the controller and routes
|
||||||
$this->call('wn:controller', [
|
$this->call('wn:controller', [
|
||||||
'model' => $modelName,
|
'model' => $modelName,
|
||||||
|
'--force' => $this->option('force'),
|
||||||
'--no-routes' => false
|
'--no-routes' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -64,13 +69,14 @@ class ResourceCommand extends BaseCommand {
|
|||||||
$this->call('wn:factory', [
|
$this->call('wn:factory', [
|
||||||
'model' => 'App\\' . $modelName,
|
'model' => 'App\\' . $modelName,
|
||||||
'--fields' => $this->factoryFields(),
|
'--fields' => $this->factoryFields(),
|
||||||
|
'--force' => $this->option('force'),
|
||||||
'--parsed' => true
|
'--parsed' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// generating database seeder
|
// generating database seeder
|
||||||
$this->call('wn:seeder', [
|
// $this->call('wn:seeder', [
|
||||||
'model' => 'App\\' . $modelName
|
// 'model' => 'App\\' . $modelName
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,10 @@ use Symfony\Component\Yaml\Yaml;
|
|||||||
class ResourcesCommand extends BaseCommand {
|
class ResourcesCommand extends BaseCommand {
|
||||||
|
|
||||||
protected $signature = 'wn:resources
|
protected $signature = 'wn:resources
|
||||||
{file : Path to the file containing resources declarations}';
|
{file : Path to the file containing resources declarations}
|
||||||
|
{--path=app : where to store the model files.}
|
||||||
|
{--force= : override the existing files}
|
||||||
|
';
|
||||||
|
|
||||||
protected $description = 'Generates multiple resources from a file';
|
protected $description = 'Generates multiple resources from a file';
|
||||||
|
|
||||||
@ -26,11 +29,13 @@ class ResourcesCommand extends BaseCommand {
|
|||||||
'--has-many' => $i['hasMany'],
|
'--has-many' => $i['hasMany'],
|
||||||
'--has-one' => $i['hasOne'],
|
'--has-one' => $i['hasOne'],
|
||||||
'--belongs-to' => $i['belongsTo'],
|
'--belongs-to' => $i['belongsTo'],
|
||||||
'--belongs-to-many' => $i['belongsToMany']
|
'--belongs-to-many' => $i['belongsToMany'],
|
||||||
|
'--path' => $this->option('path'),
|
||||||
|
'--force' => $this->option('force')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->call('migrate');
|
// $this->call('migrate');
|
||||||
|
|
||||||
$this->pivotTables = array_map(
|
$this->pivotTables = array_map(
|
||||||
'unserialize',
|
'unserialize',
|
||||||
@ -40,16 +45,18 @@ class ResourcesCommand extends BaseCommand {
|
|||||||
foreach ($this->pivotTables as $tables) {
|
foreach ($this->pivotTables as $tables) {
|
||||||
$this->call('wn:pivot-table', [
|
$this->call('wn:pivot-table', [
|
||||||
'model1' => $tables[0],
|
'model1' => $tables[0],
|
||||||
'model2' => $tables[1]
|
'model2' => $tables[1],
|
||||||
|
'--force' => $this->option('force')
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->call('wn:pivot-seeder', [
|
// $this->call('wn:pivot-seeder', [
|
||||||
'model1' => $tables[0],
|
// 'model1' => $tables[0],
|
||||||
'model2' => $tables[1]
|
// 'model2' => $tables[1],
|
||||||
]);
|
// '--force' => $this->option('force')
|
||||||
|
// ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->call('migrate');
|
// $this->call('migrate');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getResourceParams($modelName, $i)
|
protected function getResourceParams($modelName, $i)
|
||||||
@ -120,7 +127,7 @@ class ResourcesCommand extends BaseCommand {
|
|||||||
|
|
||||||
$string = "{$name};{$schema};{$rules};{$tags}";
|
$string = "{$name};{$schema};{$rules};{$tags}";
|
||||||
|
|
||||||
if($field['factory']){
|
if(isset($field['factory']) && !empty($field['factory'])){
|
||||||
$string .= ';' . $field['factory'];
|
$string .= ';' . $field['factory'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +22,7 @@ class RouteCommand extends BaseCommand {
|
|||||||
])
|
])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->save($content, './app/Http/routes.php');
|
$this->save($content, './app/Http/routes.php', "{$resource} routes", true);
|
||||||
|
|
||||||
$this->info("{$resource} routes generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getController()
|
protected function getController()
|
||||||
|
@ -6,6 +6,7 @@ class SeederCommand extends BaseCommand {
|
|||||||
protected $signature = 'wn:seeder
|
protected $signature = 'wn:seeder
|
||||||
{model : full qualified name of the model.}
|
{model : full qualified name of the model.}
|
||||||
{--count=10 : number of elements to add in database.}
|
{--count=10 : number of elements to add in database.}
|
||||||
|
{--force= : override the existing files}
|
||||||
';
|
';
|
||||||
|
|
||||||
protected $description = 'Generates a seeder';
|
protected $description = 'Generates a seeder';
|
||||||
@ -25,9 +26,7 @@ class SeederCommand extends BaseCommand {
|
|||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|
||||||
$this->save($content, $file);
|
$this->save($content, $file, $name);
|
||||||
|
|
||||||
$this->info("{$name} generated !");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getSeederName($name)
|
protected function getSeederName($name)
|
||||||
|
@ -16,8 +16,8 @@ class CommandsServiceProvider extends ServiceProvider
|
|||||||
$this->registerResourcesCommand();
|
$this->registerResourcesCommand();
|
||||||
$this->registerPivotTableCommand();
|
$this->registerPivotTableCommand();
|
||||||
$this->registerFactoryCommand();
|
$this->registerFactoryCommand();
|
||||||
$this->registerSeederCommand();
|
// $this->registerSeederCommand();
|
||||||
$this->registerPivotSeederCommand();
|
// $this->registerPivotSeederCommand();
|
||||||
// $this->registerTestCommand();
|
// $this->registerTestCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class {{name}}Table extends Migration
|
|||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
{{schema}}
|
{{schema}}
|
||||||
{{constraints}}
|
{{constraints}}
|
||||||
$table->timestamps();
|
{{additionals}}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user