/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Define new bulb
     $bulb = new Bulb();
     $bulb->name = Input::get('name');
     $bulb->ip = Input::get('ip');
     $bulb->address = Input::get('address');
     $bulb->latitude = Input::get('latitude');
     $bulb->longitude = Input::get('longitude');
     $bulb->save();
     $newBulbId = $bulb->id;
     //Add to new cluster
     //If existing
     if (Input::get('optionsRadios') == 'existing') {
         $cluster_id = Input::get('existingClusters');
         $cluster = Cluster::find($cluster_id);
         $cluster->bulbs()->attach($newBulbId);
     } else {
         $cluster = new Cluster();
         $cluster->name = Input::get('newCluster');
         $cluster->save();
         $newClusterId = $cluster->id;
         $newCluster = Cluster::find($newClusterId);
         $cluster->bulbs()->attach($newBulbId);
     }
     return Redirect::route('home.index');
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     if (Auth::check()) {
         $clusters = Cluster::all();
         $clustersCount = Cluster::all()->count();
         //Get bulbs
         $bulbs = Bulb::all();
         $bulbsCount = Bulb::all()->count();
         //Get schedules
         $schedules = Schedule::all();
         $schedulesCount = Schedule::all()->count();
         $distinct_bulbs = array_fetch(DB::select("SELECT DISTINCT bulb_id FROM poweranalyzers ORDER BY bulb_id"), 'bulb_id');
         $readings = Bulb::whereIn('id', $distinct_bulbs)->get();
         $readingsCount = count($readings);
         $markers = Cluster::find($id)->bulbs;
         $markersCount = count($markers);
         return View::make('cluster')->with('markers', $markers)->with('markersCount', $markersCount)->with('clusters', $clusters)->with('clustersCount', $clustersCount)->with('bulbs', $bulbs)->with('bulbsCount', $bulbsCount)->with('readings', $readings)->with('readingsCount', $readingsCount)->with('schedules', $schedules)->with('schedulesCount', $schedulesCount);
     }
 }