public function run()
 {
     DB::table('advisors')->delete();
     $advisors = [0 => ['first' => 'Chris', 'last' => 'Dima', 'email' => '*****@*****.**', 'password' => 'christemp1234', 'expertise' => ['MVP', 'Product Management', 'Startups']], 1 => ['first' => 'Kevin', 'last' => 'Fleming', 'email' => '*****@*****.**', 'password' => 'kevintemp1234', 'expertise' => ['Product Development', 'Product Management', 'Raising Capital']], 2 => ['first' => 'Mary', 'last' => 'Fuchs', 'email' => 'mfuchs@cceconomicdevelopment.com ', 'password' => 'marytemp1234', 'expertise' => ['Board Management', 'Grant Management', 'Tax Credits']], 3 => ['first' => 'Dave', 'last' => 'Mann', 'email' => '*****@*****.**', 'password' => 'davetemp1234', 'expertise' => ['ASP.NET', 'Amazon Web Services', 'Sharepoint']], 4 => ['first' => 'Terry', 'last' => 'Kerwin', 'email' => '*****@*****.**', 'password' => 'terrytemp1234', 'expertise' => ['Equity Compensation', 'IP Assignment & Protection', 'Raising Capital']], 5 => ['first' => 'Raymond', 'last' => 'Sarnacki', 'email' => '*****@*****.**', 'password' => 'raytemp1234', 'expertise' => ['Business Modeling', 'Project Management', 'Pitching to Investors']], 6 => ['first' => 'Craig', 'last' => 'Schroeder', 'email' => '*****@*****.**', 'password' => 'craigtemp1234', 'expertise' => ['Angel Investments', 'Consumer Finance', 'Residential Real Estate']], 7 => ['first' => 'Eamon', 'last' => 'Gallagher', 'email' => '*****@*****.**', 'password' => 'eamontemp1234', 'expertise' => ['SEC Compliance', 'Corporate Law', 'Securities Law']], 8 => ['first' => 'Mark', 'last' => 'Rybarczyk', 'email' => '*****@*****.**', 'password' => 'marktemp1234', 'expertise' => ['Financial', 'Online Video', 'Startups']], 9 => ['first' => 'Stacy', 'last' => 'Martin', 'email' => '*****@*****.**', 'password' => 'stacytemp1234', 'expertise' => ['Lease and Proposal Negotations', 'Commercial Real Estate', 'Analysis of Lease vs Buy']], 10 => ['first' => 'Paul', 'last' => 'Prestia', 'email' => '*****@*****.**', 'password' => 'paultemp1234', 'expertise' => ['Copyrights', 'Trademarks', 'Patents']], 11 => ['first' => 'Denise', 'last' => 'Smart', 'email' => '*****@*****.**', 'password' => 'denisetemp1234', 'expertise' => ['FDA Regulation of Life Science Products', 'Women Owned Business', 'FDA Regulation of Manufacturing and Development']], 12 => ['first' => 'Wilson', 'last' => 'Chu', 'email' => '*****@*****.**', 'password' => 'wilsontemp1234', 'expertise' => ['Air Emissions & Environmental', 'Emissions Control Catalysts', 'Government R&D Funding & Liason']], 13 => ['first' => 'Lars', 'last' => 'Knutsen', 'email' => '*****@*****.**', 'password' => 'larstemp1234', 'expertise' => ['Biotechnology', 'Pharmaceuticals', 'Commercializing Science']], 14 => ['first' => 'Jim', 'last' => 'Lauckner', 'email' => '*****@*****.**', 'password' => 'jimtemp1234', 'expertise' => ['Project Management', 'Recruiting', 'Industry Partnerships']], 15 => ['first' => 'Leo', 'last' => 'Daiuto', 'email' => '*****@*****.**', 'password' => 'leotemp1234', 'expertise' => ['Product Development', 'User Experience', 'Consulting']]];
     foreach ($advisors as $advisor) {
         $advisorObject = $this->advisor->createAdvisor($advisor['first'], $advisor['last'], $advisor['email'], $advisor['password']);
         foreach ($advisor['expertise'] as $expertiseName) {
             $this->expertise->connectExpertiseToAdvisor($expertiseName, $advisorObject->id);
         }
         $advisorObject->services()->attach(Service::first());
     }
     $advisorObject = $this->advisor->createAdvisor('Barry', 'White', '*****@*****.**', 'password', 100);
     $advisorObject->services()->attach(Service::first());
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $recurringAvailabilities = RecurringAvailability::all();
     $today = Day::where('date', Carbon::today())->first();
     $daysInNextTwoWeeks = Day::whereBetween('id', [$today->id, (int) $today->id + 14])->lists('date');
     $advisors = Advisor::all();
     foreach ($advisors as $advisor) {
         if ($advisor->recurringAvailabilities()->count() == 0) {
             continue;
         }
         $availabilitiesInNextTwoWeeks = [];
         foreach ($advisor->availabilities()->get() as $avail) {
             if (in_array($avail->days()->first()->date, $daysInNextTwoWeeks)) {
                 if (count(explode(':', $avail->days()->first()->pivot->time)) == 1) {
                     if (explode(' ', $avail->days()->first()->pivot->time)[1] == 'AM') {
                         if (explode(' ', $avail->days()->first()->pivot->time)[0] == '12') {
                             $time = 0;
                         } else {
                             $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0];
                         }
                     } else {
                         if (explode(' ', $avail->days()->first()->pivot->time)[0] == '12') {
                             $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0];
                         } else {
                             $time = (int) explode(' ', $avail->days()->first()->pivot->time)[0] + 12;
                         }
                     }
                 } else {
                     if (explode(' ', explode(':', $avail->days()->first()->pivot->time)[1])[1] == 'AM') {
                         if (explode(':', $avail->days()->first()->pivot->time)[0] == '12') {
                             $time = 0;
                         } else {
                             $time = (int) explode(':', $avail->days()->first()->pivot->time)[0];
                         }
                     } else {
                         if (explode(':', $avail->days()->first()->pivot->time)[0] == '12') {
                             $time = (int) explode(':', $avail->days()->first()->pivot->time)[0];
                         } else {
                             $time = (int) explode(':', $avail->days()->first()->pivot->time)[0] + 12;
                         }
                     }
                 }
                 $availabilitiesInNextTwoWeeks[] = ['date' => $avail->days()->first()->date, 'time' => $time];
             }
         }
         $recurringAvailabilitiesInNextTwoWeeks = [];
         foreach ($advisor->recurringAvailabilities()->get() as $recurAvail) {
             $difference = $recurAvail->day_of_week - Carbon::parse($today->date)->dayOfWeek;
             $this->info($difference);
             $dayOfWeekOfRecurAvail = Day::find($today->id + $difference);
             $nextWeeksDay = Day::find($today->id + $difference + 7);
             $timeOfRecurAvail = $recurAvail->time;
             if ($this->in_array_r([$dayOfWeekOfRecurAvail->date, $recurAvail->time], $availabilitiesInNextTwoWeeks)) {
                 echo 'intersection of RecurAvail ID ' . $recurAvail->id . ' at date ' . $dayOfWeekOfRecurAvail->date . "\n";
             } else {
                 // Create it for this Week
                 if ($difference > 0) {
                     Availability::createRecurringAvailability($timeOfRecurAvail, $dayOfWeekOfRecurAvail->id, $advisor->id, Service::where('name', '25 Minute Free Consultation')->first()->id, $recurAvail->location_id);
                 }
                 if (!$this->in_array_r([$nextWeeksDay->date, $recurAvail->time], $availabilitiesInNextTwoWeeks)) {
                     // Create it for next week
                     Availability::createRecurringAvailability($timeOfRecurAvail, (int) $dayOfWeekOfRecurAvail->id + 7, $advisor->id, Service::where('name', '25 Minute Free Consultation')->first()->id, $recurAvail->location_id);
                 }
             }
         }
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $service = Service::find($id);
     return View::make('services.edit', compact(['service']));
 }