/**
  * 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();
 }
 /**
  * Get the validation rules that apply to the request.
  *
  * @param DragonTypeService $typeRepo
  * @return array
  */
 public function rules(DragonTypeService $typeRepo)
 {
     return ['breed' => 'required|string', 'type' => 'required|exists:dragon_types,id', 'name' => 'required_if:type,' . $typeRepo->getIDsThatRequireNames()->implode(',') . '|string', 'collection-time' => 'required|regex:' . $this->timeRegex, 'hatching-time' => 'regex:' . $this->timeRegex, 'wood-rate' => 'integer', 'fish-rate' => 'integer', 'wood-level' => 'required_with:wood-rate|integer', 'fish-level' => 'required_with:fish-rate|integer', 'iron-time' => 'regex:' . $this->timeRegex, 'iron-rate' => 'required_with:iron-time|integer', 'iron-level' => 'required_with:iron-time|integer'];
 }
 /**
  * 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());
 }