Skip to content

Commit

Permalink
[9.x] Fix artisan make:seeder command nested namespace and class name…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
m-mohammadi1 and taylorotwell authored Mar 17, 2022
1 parent 0256484 commit 1c117ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions src/Illuminate/Database/Console/Seeds/SeederMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Console\Seeds;

use Illuminate\Console\GeneratorCommand;
use Illuminate\Support\Str;

class SeederMakeCommand extends GeneratorCommand
{
Expand Down Expand Up @@ -77,21 +78,22 @@ protected function resolveStubPath($stub)
*/
protected function getPath($name)
{
$name = str_replace('\\', '/', Str::replaceFirst($this->rootNamespace(), '', $name));

if (is_dir($this->laravel->databasePath().'/seeds')) {
return $this->laravel->databasePath().'/seeds/'.$name.'.php';
} else {
return $this->laravel->databasePath().'/seeders/'.$name.'.php';
}

return $this->laravel->databasePath().'/seeders/'.$name.'.php';
}

/**
* Parse the class name and format according to the root namespace.
* Get the root namespace for the class.
*
* @param string $name
* @return string
*/
protected function qualifyClass($name)
protected function rootNamespace()
{
return $name;
return 'Database\Seeders\\';
}
}
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Console/Seeds/stubs/seeder.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Database\Seeders;
namespace {{ namespace }};

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
Expand Down

0 comments on commit 1c117ce

Please sign in to comment.