Orangehill\Iseed\Iseed::generateSeed PHP Метод

generateSeed() публичный Метод

Generates a seed file.
public generateSeed ( string $table, string $database = null, integer $max, string $prerunEvent = null, $postrunEvent = null ) : boolean
$table string
$database string
$max integer
$prerunEvent string
Результат boolean
    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;
    }

Usage Example

Пример #1
0
 /**
  * Generates a seed file.
  *
  * @param string $table
  * @param string $database
  * @param int $max
  * @return bool 
  * @throws Orangehill\Iseed\TableNotFoundException
  * @static 
  */
 public static function generateSeed($table, $database = null, $max = 0)
 {
     return \Orangehill\Iseed\Iseed::generateSeed($table, $database, $max);
 }