File tree Expand file tree Collapse file tree
user_guide_src/source/database Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,20 +129,31 @@ public function call(string $class)
129129 {
130130 throw new \InvalidArgumentException ('No Seeder was specified. ' );
131131 }
132-
133- $ path = $ this ->seedPath .str_replace ('.php ' , '' , $ class ).'.php ' ;
134-
135- if (! is_file ($ path ))
136- {
137- throw new \InvalidArgumentException ('The specified Seeder is not a valid file: ' . $ path );
138- }
139-
140- if (! class_exists ($ class , false ))
141- {
142- require $ path ;
143- }
144132
145- $ seeder = new $ class ($ this ->config );
133+ $ path = str_replace ('.php ' , '' , $ class ).'.php ' ;
134+
135+ // If we have namespaced class, simply try to load it.
136+ if (strpos ($ class , '\\' ) !== false )
137+ {
138+ $ seeder = new $ class ($ this ->config );
139+ }
140+ // Otherwise, try to load the class manually.
141+ else
142+ {
143+ $ path = $ this ->seedPath .$ path ;
144+
145+ if (! is_file ($ path ))
146+ {
147+ throw new \InvalidArgumentException ('The specified Seeder is not a valid file: ' . $ path );
148+ }
149+
150+ if (! class_exists ($ class , false ))
151+ {
152+ require $ path ;
153+ }
154+
155+ $ seeder = new $ class ($ this ->config );
156+ }
146157
147158 $ seeder ->run ();
148159
Original file line number Diff line number Diff line change @@ -49,6 +49,15 @@ but organize the tasks into separate seeder files::
4949 }
5050 }
5151
52+ You can also use a fully-qualified class name in the **call() ** method, allowing you to keep your seeders
53+ anywhere the autoloader can find them. This is great for more modular code bases::
54+
55+ public function run()
56+ {
57+ $this->call('UserSeeder');
58+ $this->call('My\Database\Seeds\CountrySeeder');
59+ }
60+
5261Using Seeders
5362=============
5463
You can’t perform that action at this time.
0 commit comments