public function updateSiteRelay($site_id, $relay_id, $status)
 {
     $site = Site::find($site_id);
     if (!$site->Zone) {
         $site_relays = $site->Relays;
         if (!$site_relays->count()) {
             for ($i = 0; $i < 6; $i++) {
                 Relay::create(array('site_id' => $site_id, 'relay_id' => $i, 'status' => 'False'));
             }
         }
         $site_relay = Relay::withSiteAndRelay($site_id, $relay_id)->get()->first();
         $relay = Relay::find($site_relay->id);
         if ($status == 0) {
             $statusCommand = 0;
             $statusString = 'Off';
             $status = 'False';
         } else {
             $statusCommand = 1;
             $statusString = 'On';
             $status = 'True';
         }
         $relay->status = $status;
         $relay->save();
         $entry = new Record();
         $entry->site_id = $site_id;
         $entry->site_name = $site->name;
         $entry->switch = $relay->relay_id;
         $entry->status = $statusString;
         $entry->command = $statusCommand;
         $entry->save();
     } else {
         $message = 'This site is zoned. Please update changes to the zone!';
         Session::put('message', $message);
     }
 }
 public function OffCommand($zone_id, $relay_id)
 {
     $zone = Zone::find($zone_id);
     $zone_sites = $zone->Sites;
     $zone_relays = $zone->Relays;
     if (!$zone_relays->count()) {
         for ($i = 0; $i < 6; $i++) {
             ZoneRelay::create(array('zone_id' => $zone_id, 'relay_id' => $i, 'status' => 'False'));
         }
     }
     $zone_relay = ZoneRelay::withZoneAndRelay($zone_id, $relay_id)->get()->first();
     $relay = ZoneRelay::find($zone_relay->id);
     $relay->status = 'False';
     $relay->save();
     $entry = new ZoneRecord();
     $entry->zone_id = $zone->id;
     $entry->zone_name = $zone->name;
     $entry->switch = $relay->relay_id;
     $entry->status = 'Off';
     $entry->command = 0;
     $entry->admin_id = Auth::admin()->get()->id;
     $entry->save();
     foreach ($zone_sites as $zone_site) {
         $site_relays = $zone_site->Relays;
         if (!$site_relays->count()) {
             for ($i = 0; $i < 6; $i++) {
                 Relay::create(array('site_id' => $zone_site->id, 'relay_id' => $i, 'status' => 'False'));
             }
         }
         $site_relay = Relay::withSiteAndRelay($zone_site->id, $zone_relay->relay_id)->get()->first();
         $relay = Relay::find($site_relay->id);
         $relay->status = 'False';
         $relay->save();
         $entry = new Record();
         $entry->site_id = $zone_site->id;
         $entry->site_name = $zone_site->name;
         $entry->switch = $relay->relay_id;
         $entry->status = 'Off';
         $entry->command = 0;
         $entry->save();
     }
     return Redirect::to('zone/' . $zone_id);
 }