/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $this->validate($request, ['name' => 'required|max:255', 'building_sn' => 'required|max:255'], ['required' => 'The :attribute field is required', 'max' => 'The length of :attribute can not bigger than 255']); $building = Building::find($id); $input = $request->all(); $building->fill($input); if (!$building->save()) { abort(500, 'Could not save building'); } return $building; }
public function healWall(Request $request, $city_id) { $city = City::where('id', $city_id)->first(); if (!$this->validateOwner($city)) { return redirect('/home')->withErrors('Nem a te városod'); } $wall = $city->building_slot->wall; $wall = Building::find($wall); $this->validate($request, ['health' => 'required|integer|max:100']); $health = $request->input('health'); $price = ['iron' => $health, 'food' => $health, 'stone' => $health, 'lumber' => $health]; $time = $health; $this->heal($city, $wall, $price, $time, $health); return redirect("/city/{$city_id}/wall"); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { $building = Building::find($this->buildings); switch ($this->method()) { case 'GET': case 'DELETE': return []; case 'POST': return ['code' => 'required|unique:buildings|max:20', 'name' => 'required|max:254']; case 'PUT': case 'PATCH': return ['code' => "required|unique:buildings,code,{$building->id}|max:20", 'name' => 'required|max:254']; default: break; } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { return Building::find($id); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, Request $request) { $city = City::find($id); $buildingIds = $this->getIdArray($request->input('buildings')); $result = $this->arrayDiffNotUnique($buildingIds, $this->getIdArray($city->buildings)); $city->buildings()->attach($result); $city->save(); $building = Building::find($result); CityEffectApplier::applyBuildEffect($building[0], $city); $resource = $building[0]->resource; $cityResource = $city->resource; $cityResource->substractResource($resource); $cityResource->save(); $return = City::find($id); $return->buildings; $return->resource; $return->income; return $return; }