Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Add a flag that will also create the Laravel database factory
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanHolmes committed Mar 5, 2020
1 parent b2394e1 commit 1e46b34
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/CreatePoserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class CreatePoserFactory extends GeneratorCommand
{
protected $signature = 'make:poser {name : The name of the Poser Factory}
{--m|model= : The model that this factory is linked too}';
{--m|model= : The model that this factory is linked too}
{--f|factory : Also create the Laravel database factory}';

protected $description = 'Creates a Poser Model Factory with the given name';

Expand Down Expand Up @@ -88,7 +89,32 @@ public function handle()
$this->info($name . " successfully created at " . $destination);
$this->line("");
$this->line("Remember, you should have a corresponding model, database factory and migration");

if ($this->option('factory')) {
$this->line("");
$this->line("Creating database factory");

$this->createFactory($linkedModelNamespace);
}

$this->line("");
$this->info("Please consider starring the repo at https://github.com/lukeraymonddowning/poser");
}

/**
* Create a database factory for the model.
*
* @param string $modelNamespace
*
* @return void
*/
protected function createFactory($modelNamespace)
{
$factory = Str::studly(class_basename($modelNamespace));

$this->call('make:factory', [
'name' => "{$factory}Factory",
'--model' => $this->qualifyClass($this->getNameInput()),
]);
}
}

0 comments on commit 1e46b34

Please sign in to comment.