10
10
11
11
class SeedCommand extends Command
12
12
{
13
- const SEEDERS_NAMESPACE_PREFIX = 'Database\Seeders \\' ;
13
+ const SEEDERS_NAMESPACE_PREFIX = 'Database \\ Seeders \\' ;
14
14
15
15
/** @var Filesystem */
16
16
protected $ filesystem ;
@@ -22,6 +22,8 @@ class SeedCommand extends Command
22
22
*/
23
23
protected $ signature = 'cmd:db:seed
24
24
{--c|class= : The seeder to run }
25
+ {--all : Run all registered seed files }
26
+ {--force : Force the operation to run when in production }
25
27
' ;
26
28
27
29
/**
@@ -41,15 +43,33 @@ public function __construct()
41
43
42
44
public function handle ()
43
45
{
46
+ if ($ this ->option ('all ' )){
47
+ $ this ->runSeed ();
48
+ exit ;
49
+ }
50
+
44
51
$ seeders = Arr::wrap ($ this ->option ('class ' )) ?: $ this ->getSeedClass ();
45
52
46
53
foreach ($ seeders as $ seeder ) {
47
- $ this ->call ('db:seed ' , [
48
- '--class ' => $ this ->getSeederWithNamespace ($ seeder ),
49
- ]);
54
+ $ this ->runSeed ($ seeder );
50
55
}
51
56
}
52
57
58
+ private function runSeed (?string $ class = null ) :void
59
+ {
60
+ $ options = [];
61
+
62
+ if ($ class ){
63
+ $ options ['--class ' ] = $ this ->getSeederWithNamespace ($ class );
64
+ }
65
+
66
+ if ($ force = $ this ->option ('force ' )){
67
+ $ options ['--force ' ] = $ force ;
68
+ }
69
+
70
+ $ this ->call ("db:seed " , $ options );
71
+ }
72
+
53
73
private function getSeederWithNamespace (string $ seeder ) :string
54
74
{
55
75
if (Str::startsWith ($ seeder , self ::SEEDERS_NAMESPACE_PREFIX )){
0 commit comments