/** * 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'); }
public function testNewClusterWithNullParent() { $node = new Cluster(['name' => 'Root 3']); $this->assertTrue($node->isRoot()); $node->save(); $this->assertTrue($node->isRoot()); $node->makeRoot(); $this->assertTrue($node->isRoot()); }