PHP code example of antonyz89 / yii2-seeder

1. Go to this page and download the library: Download antonyz89/yii2-seeder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antonyz89 / yii2-seeder example snippets




namespace console\seeder\tables;

use common\models\user\User;
use console\seeder\DatabaseSeeder;
use antonyz89\seeder\TableSeeder;
use Yii;

class UserTableSeeder extends TableSeeder
{
    function run()
    {
        loop(function ($i) {
            $this->insert(User::tableName(), [
                'email' => "[email protected]",
                'name' => $this->faker->name,
                'document' => $this->faker->numerify('##############'),
                'street' => $this->faker->streetName,
                'number' => $this->faker->numerify('###'),
                'zip_code' => $this->faker->postcode,
                'city' => $this->faker->city,
                'status' => User::STATUS_USER_ACTIVE
                //created_at and updated_at are automatically added
            ]);
        }, DatabaseSeeder::USER_COUNT);
    }
}

public $skipTruncateTables = true;

public $skipTruncateTables = false;

...

// truncate table
$this->disableForeignKeyChecks();
$this->truncateTable(/* table names */);
$this->enableForeignKeyChecks();

class DatabaseSeeder extends TableSeeder
{

    const MODEL_COUNT = 10;

    public function run()
    {
        ModelTableSeeder::create()->run();
    }

}