Skip to content

Commit 63bb589

Browse files
Add callOnce to Seeder (#39812)
1 parent ee5efbc commit 63bb589

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Illuminate/Database/Seeder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ abstract class Seeder
2323
*/
2424
protected $command;
2525

26+
/**
27+
* Seeders that have been called at least one time.
28+
*
29+
* @var array
30+
*/
31+
protected static $called = [];
32+
2633
/**
2734
* Run the given seeder class.
2835
*
@@ -53,6 +60,8 @@ public function call($class, $silent = false, array $parameters = [])
5360
if ($silent === false && isset($this->command)) {
5461
$this->command->getOutput()->writeln("<info>Seeded:</info> {$name} ({$runTime}ms)");
5562
}
63+
64+
static::$called[] = $class;
5665
}
5766

5867
return $this;
@@ -82,6 +91,22 @@ public function callSilent($class, array $parameters = [])
8291
$this->call($class, true, $parameters);
8392
}
8493

94+
/**
95+
* Run the given seeder class once.
96+
*
97+
* @param array|string $class
98+
* @param bool $silent
99+
* @return void
100+
*/
101+
public function callOnce($class, $silent = false, array $parameters = [])
102+
{
103+
if (in_array($class, static::$called)) {
104+
return;
105+
}
106+
107+
$this->call($class, $silent, $parameters);
108+
}
109+
85110
/**
86111
* Resolve an instance of the given seeder class.
87112
*

0 commit comments

Comments
 (0)