/**
  * @return Collection
  */
 public function getIDsThatRequireNames()
 {
     // IDs need to be strings in the json for the comparison...
     return DragonType::where('name', 1)->pluck('id')->map(function ($item, $key) {
         return (string) $item;
     });
 }
 /**
  * Set data from a request for the given dragon
  *
  * @param Dragon $dragon
  * @param mixed[] $requestData
  */
 public function setData($dragon, $requestData)
 {
     $dragon->breed = $requestData['breed'];
     $dragon->hatching_time = $requestData['hatching-time'];
     $dragon->fish_start_level = zeroIsNull($requestData['fish-level']);
     $dragon->wood_start_level = zeroIsNull($requestData['wood-level']);
     $dragon->iron_start_level = zeroIsNull($requestData['iron-level']);
     if ($this->dragonTypeService->getIDsThatRequireNames()->contains($requestData['type'])) {
         $dragon->name = $requestData['name'];
     } else {
         $dragon->name = null;
     }
     $dragon->dragonType()->associate(DragonType::find($requestData['type']));
     $dragon->collectTime()->associate($this->collectTimeService->getWhereMaxLevelIs($requestData['collection-time']));
     $dragon->collectRateFish()->associate($this->collectRateService->getWhereMaxLevelIs($requestData['fish-rate']));
     $dragon->collectRateWood()->associate($this->collectRateService->getWhereMaxLevelIs($requestData['wood-rate']));
     $dragon->save();
     $ironData = $dragon->collectIronData->where('level', (int) Setting::get('max-level'))->first();
     if (!$ironData) {
         $ironData = new CollectIronData();
         $ironData->level = Setting::get('max-level');
         $dragon->collectIronData()->save($ironData);
     }
     $ironData->fill(['rate' => $requestData['iron-rate'], 'time' => $requestData['iron-time']]);
     $ironData->save();
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $type = DragonType::find($id);
     if ($type->dragons->count()) {
         Notification::add('error', $type->type . ' cannot be deleted; there are dragons assigned to it');
         return Redirect::route('dragon-type.show', ['id' => $id]);
     } else {
         $type->delete();
         Notification::add('success', $type->type . ' deleted');
         return Redirect::route('dragon-type.index');
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function edit($id)
 {
     /** @noinspection PhpUndefinedMethodInspection */
     return view('dragon.edit')->with('dragon', Dragon::find($id))->with('types', DragonType::orderBy('type')->pluck('type', 'id'))->with('namedTypesArray', $this->dragonTypeService->getIDsThatRequireNames()->toJson());
 }