コード例 #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return Response
  */
 public function store(Request $request)
 {
     $building = new Building();
     $building->name = $request->input("name");
     $building->address = $request->input("address");
     $building->save();
     return redirect()->route('buildings.index')->with('message', 'Item created successfully.');
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $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 = new Building($request->all());
     $building['user_id'] = $this->user['id'];
     if (!$building->save()) {
         abort(500, 'Could not save building');
     }
     return $building;
 }
コード例 #3
0
 /**
  * @param City $city
  * @param Building $building
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 private function setWorkers(City $city, Building $building, Request $request)
 {
     $workers = $request->input('workers');
     // validate the request's number
     if ($workers > $building->level * 10 || $workers < 0) {
         return redirect($request->url())->withErrors(["no_more_worker" => "Az épületben nem dolgozhat ennyi munkás"]);
     }
     // check if the user want to add or remove workers.
     $diff = $workers - $building->workers;
     if ($city->hasEnoughHumanResources(['workers' => $diff])) {
         $city->human_resources->subtract(['workers' => $diff]);
         $building->workers = $workers;
         $building->save();
         return redirect()->back();
     }
     return redirect()->back()->withErrors(['not_enough_worker' => "Nincs elég munkás"]);
 }
コード例 #4
0
 public static function buildingWearing(Building $building)
 {
     $now = Carbon::now();
     $workers = $building->workers;
     if ($workers == 0) {
         $workers = 0.5;
     }
     $time = $building->updated_at->diffInSeconds($now);
     $wearing = $time / 3600 * ($workers * 0.1);
     $building->health -= $wearing;
     $building->save();
 }