Skip to content

Commit f1eab0a

Browse files
authored
Fix model namespace in the generated factory class. (#512)
1 parent 07a0855 commit f1eab0a

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

src/Generators/FactoryGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ protected function populateStub(string $stub, Model $model)
8383
$stub = str_replace('definition()', 'definition(): array', $stub);
8484
}
8585

86+
$stub = str_replace('{{ namespace }}', 'Database\Factories' . ($model->namespace() ? '\\' . $model->namespace() : ''), $stub);
8687
$stub = str_replace('use {{ namespacedModel }};', $this->buildImports($model), $stub);
8788

8889
return $stub;

stubs/factory.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Database\Factories;
3+
namespace {{ namespace }};
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Illuminate\Support\Str;

tests/fixtures/factories/nested-components.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Database\Factories;
3+
namespace Database\Factories\Admin;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Illuminate\Support\Str;

tests/fixtures/factories/nested-models.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Database\Factories;
3+
namespace Database\Factories\Screening;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
66
use Illuminate\Support\Str;

0 commit comments

Comments
 (0)