public function generateSeed($table, $database = null, $max = 0, $prerunEvent = null, $postrunEvent = null)
{
if (!$database) {
$database = config('database.default');
}
$this->databaseName = $database;
// Check if table exists
if (!$this->hasTable($table)) {
throw new TableNotFoundException("Table {$table} was not found.");
}
// Get the data
$data = $this->getData($table, $max);
// Repack the data
$dataArray = $this->repackSeedData($data);
// Generate class name
$className = $this->generateClassName($table);
// Get template for a seed file contents
$stub = $this->files->get($this->getStubPath() . '/seed.stub');
// Get a seed folder path
$seedPath = $this->getSeedPath();
// Get a app/database/seeds path
$seedsPath = $this->getPath($className, $seedPath);
// Get a populated stub file
$seedContent = $this->populateStub($className, $stub, $table, $dataArray, null, $prerunEvent, $postrunEvent);
// Save a populated stub
$this->files->put($seedsPath, $seedContent);
// Update the DatabaseSeeder.php file
return $this->updateDatabaseSeederRunMethod($className) !== false;
}