/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $connection = config('ab.connection');
     // Create experiments table.
     if (!Schema::connection($connection)->hasTable('experiments')) {
         Schema::connection($connection)->create('experiments', function ($table) {
             $table->increments('id');
             $table->string('name');
             $table->integer('visitors')->unsigned()->default(0);
             $table->integer('engagement')->unsigned()->default(0);
             $table->timestamps();
         });
     }
     // Create goals table.
     if (!Schema::connection($connection)->hasTable('goals')) {
         Schema::connection($connection)->create('goals', function ($table) {
             $table->increments('id');
             $table->string('name');
             $table->string('experiment');
             $table->integer('count')->unsigned()->default(0);
             $table->timestamps();
         });
     }
     $this->info('Database schema initialized.');
     $experiments = config('ab.experiments');
     if (!$experiments or empty($experiments)) {
         return $this->error('No experiments configured.');
     }
     $goals = config('ab.goals');
     if (!$goals or empty($goals)) {
         return $this->error('No goals configured.');
     }
     // Populate experiments and goals.
     foreach ($experiments as $experiment) {
         Experiment::firstOrCreate(['name' => $experiment]);
         foreach ($goals as $goal) {
             Goal::firstOrCreate(['name' => $goal, 'experiment' => $experiment]);
         }
     }
     $this->info('Added ' . count($experiments) . ' experiments.');
 }
 /**
  * Mark a goal as completed for the current experiment.
  *
  * @return void
  */
 public function complete($name)
 {
     // Only complete once per experiment.
     if ($this->session->get("completed_{$name}")) {
         return;
     }
     $goal = Goal::firstOrCreate(['name' => $name, 'experiment' => $this->experiment()]);
     Goal::where('name', $name)->where('experiment', $this->experiment())->update(['count' => $goal->count + 1]);
     // Mark current experiment as completed.
     $this->session->set("completed_{$name}", 1);
 }