-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add make:factory. add all option to make:model to generate entire res…
…ource
- Loading branch information
1 parent
5c48ed1
commit a6ffd8b
Showing
4 changed files
with
132 additions
and
2 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Console\Factories; | ||
|
||
use Illuminate\Console\GeneratorCommand; | ||
|
||
class FactoryMakeCommand extends GeneratorCommand | ||
{ | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'make:factory'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new model factory'; | ||
|
||
/** | ||
* The type of class being generated. | ||
* | ||
* @var string | ||
*/ | ||
protected $type = 'Factory'; | ||
|
||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return __DIR__.'/stubs/factory.stub'; | ||
} | ||
|
||
/** | ||
* Build the class with the given name. | ||
* | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function buildClass($name) | ||
{ | ||
$model = $this->qualifyClass($this->argument('name')); | ||
|
||
return str_replace( | ||
'DummyModel', $model, parent::buildClass($name) | ||
); | ||
} | ||
|
||
/** | ||
* Get the destination class path. | ||
* | ||
* @param string $name | ||
* @return string | ||
*/ | ||
protected function getPath($name) | ||
{ | ||
$name = str_replace( | ||
['\\', '/'], '', $this->argument('name') | ||
).'Factory'; | ||
|
||
return $this->laravel->databasePath()."/factories/{$name}.php"; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/Illuminate/Database/Console/Factories/stubs/factory.stub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use Fake\Generator as Faker; | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Model Factories | ||
|-------------------------------------------------------------------------- | ||
| | ||
| This directory should contain each of the model factory definitions for | ||
| your application. Factories provide a convenient way to generate new | ||
| model instances for testing / seeding your application's database. | ||
| | ||
*/ | ||
|
||
$factory->define(DummyModel::class, function (Faker $faker) { | ||
return [ | ||
// | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters