public function __construct($object, $data) { $this->data = $data; \DB::beginTransaction(); try { switch ($object) { case 'star': $this->toChange = \App\Star::find($data['id']); $this->address = $this->toChange->address; $this->changeStar(); $this->finalize(); break; case 'planet': $this->toChange = \App\Planet::find($data['id']); $this->address = $this->toChange->star->address; $this->changePlanet(); $this->finalize(); break; case 'bari': $this->toChange = \App\Bariplanet::find($data['id']); $this->address = $this->toChange->center->address; $this->changePlanet(); $this->finalize(); break; case 'multi': $this->toChange = \App\Baricenter::find($data['id']); $this->address = $this->toChange->address; $this->changeMulti(); $this->finalize(); break; } } catch (\PDOException $e) { $this->rollback(); } }
public function __construct($id) { //construct new StarInfo dew to the database id $bari = \App\Baricenter::find($id); foreach ($bari->stars()->get() as $star) { $this->stars[$star->id] = new starInfo($star); } $this->stars['self'] = $bari->id; //construct planets array with new PlanetInfo objects foreach ($bari->planets()->get() as $planet) { $this->planets[$planet->id] = new planetInfo($planet); } }
public function __construct(array $data) { parent::__construct($data); $this->address = \App\Address::find($data['address']); switch ($data['object']) { case 'star': $this->centerObject = \App\Star::find($data['objectId']); break; case 'multi': $this->centerObject = \App\Baricenter::find($data['objectId']); break; } }
<label for="codeD"> Code in the system</label> <input type="text" name="code" value="{{$starData->code}}" id="codeD"> <button type="submit" class="btn btn-warning">Change</button> </form> <h4 class="white">Delete</h4> <form method="get" action="{{route('changeObject')}}"> <input type="hidden" value="{{$data['id']}}" name="id"> <input type="hidden" value="star" name="type"> <input type="hidden" value="delete" name="action"> <button type="submit" class="btn btn-danger">Delete</button> </form> @endif @if($data['type'] == 'multi') <?php $centerData = \App\Baricenter::find($data['id']); $markedStars = $centerData->stars()->get(); $allStars = $centerData->address->stars()->get(); ?> <form class="form-inline" method="get" action="{{route('changeObject')}}"> <input type="hidden" value="{{$data['id']}}" name="id"> <input type="hidden" value="{{$data['type']}}" name="type"> <input type="hidden" value="change" name="action"> <p>Barycenter of the stars</p> <ul> @foreach($markedStars as $star) <li>{{\App\Myclasses\Arrays::nameStar($star)}}</li> @endforeach </ul> <label for="stars">Select stars in the system to assign</label> <select name="stars[]" id="stars" multiple="multiple">
protected function saveCenter() { $array = ['address_id' => $this->data['address']]; $this->center = \App\Baricenter::create($array); $this->addStars(); }