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); } }
public function __construct() { $this->connect(); $this->connection = Connection::instance(); $this->collection = $this->setCollection($this->collection); }
/** * Perform post-registration booting of services. * * @return void */ public function boot() { $connection = MongoConnection::instance(); $this->app->instance('connection', $connection); }
/** * 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)); }