public function run()
 {
     $candidate = new Candidate();
     $collection_name = $candidate->getCollectionName();
     $connection = \Hexcores\MongoLite\Connection::instance();
     $connection->collection($collection_name)->drop();
     $faker = Factory::create();
     $parties = mongo_lite('party')->all();
     for ($i = 0; $i < 20; $i++) {
         $residency = $faker->state() . ' / ' . $faker->city();
         $constituency = $faker->city() . ' / ' . $faker->cityPrefix() . ' / ' . $faker->state();
         $pcode = $this->getRandomPcode();
         $data = ['name' => $faker->name, 'gender' => $faker->randomElement(['male', 'female']), 'legislature' => $faker->randomElement(['amyotha_hluttaw', 'pyithu_hluttaw', 'region', 'state']), 'nrc' => $faker->bothify('##/???(N)######'), 'dob' => new \MongoDate($faker->dateTime($max = 'now')->format('U')), 'education' => $faker->words($nb = rand(0, 4)), 'occupation' => $faker->words($nb = rand(0, 4)), 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu']), 'party_id' => $this->getPartyId($parties), 'residency' => ['type' => $residency, 'name' => $residency . ' name', 'ST_PCODE' => $pcode['ST_PCODE'], 'DT_PCODE' => $pcode['DT_PCODE'], 'count' => $faker->randomNumber(5)], 'constituency' => ['type' => $constituency, 'name' => $faker->word(), 'ST_PCODE' => $pcode['ST_PCODE'], 'DT_PCODE' => $pcode['DT_PCODE'], 'count' => $faker->randomNumber(5)], 'father' => ['name' => $faker->name, 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu'])], 'mother' => ['name' => $faker->name, 'religion' => $faker->randomElement(['Buddhism', 'Christian', 'Islam', 'Hindu'])]];
         $candidate->getCollection()->insert($data);
     }
 }
 /**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot()
 {
     $connection = MongoConnection::instance();
     $this->app->instance('connection', $connection);
 }
 /**
  * Constructor method for abstract model class
  */
 public function __construct()
 {
     $this->connection = app('connection');
     $this->collection = new Query($this->connection->collection($this->getCollectionName()));
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $config = $this->app['config']->get('mongo_lite');
     Connection::connect($config['host'], $config['port'], $config['database'], $config['user'], $config['password']);
 }
Example #5
0
 private function connect()
 {
     Connection::connect(env('DB_HOST', 'localhost'), env('DB_PORT', '27017'), env('DB_DATABASE', 'mmelection'));
 }
Example #6
0
 /**
  * Helper for mongo lite query instance.
  *
  * @param  string $collection
  * @param  string $name
  * @return \Hexcores\MongoLite\Query
  */
 function mongo_lite($collection, $name = 'default')
 {
     $connection = \Hexcores\MongoLite\Connection::instance($name);
     return new \Hexcores\MongoLite\Query($connection->collection($collection));
 }