Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Illuminate/Database/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ abstract class Seeder
*/
protected $command;

/**
* Seeders that have been called at least one time.
*
* @var array
*/
protected static $called = [];

/**
* Run the given seeder class.
*
Expand Down Expand Up @@ -53,6 +60,8 @@ public function call($class, $silent = false, array $parameters = [])
if ($silent === false && isset($this->command)) {
$this->command->getOutput()->writeln("<info>Seeded:</info> {$name} ({$runTime}ms)");
}

static::$called[] = $class;
}

return $this;
Expand Down Expand Up @@ -82,6 +91,22 @@ public function callSilent($class, array $parameters = [])
$this->call($class, true, $parameters);
}

/**
* Run the given seeder class once.
*
* @param array|string $class
* @param bool $silent
* @return void
*/
public function callOnce($class, $silent = false, array $parameters = [])
{
if (in_array($class, static::$called)) {
return;
}

$this->call($class, $silent, $parameters);
}

/**
* Resolve an instance of the given seeder class.
*
Expand Down