PHP code example of brad-denver / paris-seeder

1. Go to this page and download the library: Download brad-denver/paris-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/ */

    

brad-denver / paris-seeder example snippets


Seeder::seed('Seeds\Roles', 2, null, function($record) {
  Seeder::seed('Seeds\Users', 2, array('role_id'=>$record->id));
});

ORM::configure('mysql:host=localhost;dbname=my_database');
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');

namespace Seeds;

class Roles extends \Model {

  /*
  * use the Paris filter pattern to create a new fake record
  */
  public function create_fake($orm, $faker) {
    $orm->create(array(
      'title' => $faker->word
    ));
    return $orm;
  }
}

class Users extends \Model {

  /*
  * use the Paris filter pattern to create a new fake record
  */
  public function create_fake($orm, $faker) {
    $orm->create(array(
      'name' => $faker->name,
      'role_id' => $faker->randomDigit
    ));
    return $orm;
  }
}


Seeder::seed('Seeds\Users', 5);

Seeder::seed('Seeds\Users', 5, array('role_id'=>2));

Seeder::seed('Seeds\Roles', 2, null, function($record) {
  Seeder::seed('Seeds\Users', 5, array('role_id'=>$record->id));
});

$faker = Faker\Factory::create('fr_FR'); // create a French faker
Seeder::seed('Seeds\Users', 5, null, null, $faker);

// a paris model pointing to our production roles table
$source_model = Model::factory('Roles', 'remote');
// a paris model pointing to our dev roles table that needs to mirror production
$target_model = Model::factory('Roles', 'local');
Seeder::replicate($source_model, $target_model);

Seeder::delete_all('Seeds\Users');

Seeder::delete_all_and_seed('Seeds\Users', 5);