Skip to content

Commit 1c117ce

Browse files
[9.x] Fix artisan make:seeder command nested namespace and class name problem (#41534)
* fix make:seeder command nested namespace and class name problem * change make:seeder generated stub file * fix style * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 0256484 commit 1c117ce

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/Illuminate/Database/Console/Seeds/SeederMakeCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Database\Console\Seeds;
44

55
use Illuminate\Console\GeneratorCommand;
6+
use Illuminate\Support\Str;
67

78
class SeederMakeCommand extends GeneratorCommand
89
{
@@ -77,21 +78,22 @@ protected function resolveStubPath($stub)
7778
*/
7879
protected function getPath($name)
7980
{
81+
$name = str_replace('\\', '/', Str::replaceFirst($this->rootNamespace(), '', $name));
82+
8083
if (is_dir($this->laravel->databasePath().'/seeds')) {
8184
return $this->laravel->databasePath().'/seeds/'.$name.'.php';
82-
} else {
83-
return $this->laravel->databasePath().'/seeders/'.$name.'.php';
8485
}
86+
87+
return $this->laravel->databasePath().'/seeders/'.$name.'.php';
8588
}
8689

8790
/**
88-
* Parse the class name and format according to the root namespace.
91+
* Get the root namespace for the class.
8992
*
90-
* @param string $name
9193
* @return string
9294
*/
93-
protected function qualifyClass($name)
95+
protected function rootNamespace()
9496
{
95-
return $name;
97+
return 'Database\Seeders\\';
9698
}
9799
}

src/Illuminate/Database/Console/Seeds/stubs/seeder.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\Seeders;
3+
namespace {{ namespace }};
44

55
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
66
use Illuminate\Database\Seeder;

0 commit comments

Comments
 (0)