Skip to content

Commit

Permalink
Tweak factory generator
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusBoa committed Oct 23, 2020
1 parent dc08cba commit 54d5ddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ protected function buildClass($name)

$model = class_basename($namespaceModel);

$namespaceFactory = Str::ucfirst(str_replace('Factory', '', $name));
$factory = class_basename($namespaceFactory);

if (Str::startsWith($namespaceModel, 'App\\Models')) {
$namespace = Str::beforeLast('Database\\Factories\\'.Str::after($namespaceModel, 'App\\Models\\'), '\\');
} else {
Expand All @@ -80,6 +83,8 @@ protected function buildClass($name)
'DummyModel' => $model,
'{{ model }}' => $model,
'{{model}}' => $model,
'{{ factory }}' => $factory,
'{{factory}}' => $factory,
];

return str_replace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace {{ factoryNamespace }};
use Illuminate\Database\Eloquent\Factories\Factory;
use {{ namespacedModel }};

class {{ model }}Factory extends Factory
class {{ factory }}Factory extends Factory
{
/**
* The name of the factory's corresponding model.
Expand Down

0 comments on commit 54d5ddc

Please sign in to comment.