示例#1
0
 /**
  * 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');
 }