public function finishEvent() { $resources = DB::table('events_resources')->where('event_id', $this->id)->get(); foreach ($resources as $resource) { $resourceRecord = Resource::find($resource->resource_id); if ($resourceRecord) { $resourceRecord->backToInventory($resource->amount); } } $this->active = 0; $this->save(); }
/** * Creates a new lease and returns some basic details about it. * Request might also contain optional $_GET['duration'] parameter, otherwise a default value will be used. * * @param $string * @param Request $request * @return mixed */ public function lease($string, Request $request) { $picker = $this->pickResource($string); if ($picker['error']) { return $this->respondWithError($picker['error']); } $resource = Resource::find($picker['resourceId']); $leaseParams = Lease::stub($resource->id, null, $request->duration); $lease = Lease::create($leaseParams); $response = ['leased_at' => Carbon::now(), 'links' => ['rel' => 'details', 'uri' => '/leases/' . $lease->uuid]]; return $this->respond($response, 201); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $resource = Resource::find($id); // return var_dump($resource); $allTopics = Topic::all()->sortBy('name'); $topics = []; foreach ($allTopics as $topic) { $topics += [$topic->id => $topic->name]; if ($resource->topics->has($topic->id)) { } } // return view('resources.edit')->with('resource', $resource); return view('admin.resources.edit')->with('resource', $resource)->with('topics', $topics); }
/** * Shows a particular resource * * @param $id * @return \Illuminate\View\View */ public function show($id) { //abort('404'); //$resource = Resource::find($id); // To throw an exception //$resource = Resource::findOrFail($id); $resource = Resource::find($id); if (!$resource) { // I think findOPrFail is equivalent abort(404); # @TODO Check what happens here and compare with the findOrFail } //dd($resource); return view('resources.show', compact('resource')); }
public function postResources() { $id = \Input::get('pk'); $name = \Input::get('name'); $value = \Input::get('value'); $resource = Resource::find($id); if ($resource->setVal($name, $value)) { return \Response::json(['status' => 1]); } else { return \Response::json(['status' => 0]); } // $topic = App\Topic::find(\Input::get('pk')); // $topic->name = Input::get('value'); // if($topic->save()){ // return Response::json(['status' => 1, 'name' => $topic->name]); // } else { // return Response::json(['status' => 0]); // } }
public function payForUnits($unitsToBuy, $army, $city) { $prices = ResourceController::getPricesForUnits($army->units, $city); $unitsToBuy = $this->getBuyCount($army->units, $unitsToBuy); foreach ($prices as $price) { foreach ($unitsToBuy as $unit) { if ($price['id'] == $unit['resource_id']) { $price->multiplyResource($unit['countToBuy']); } } } $resource = Resource::find($city->resource->id); $resource->substractResourceArray($prices); $resource->save(); }
public function destroy($id) { if (!Auth::check()) { return response()->json($this->notLoginJson, 401); } else { $user = Auth::user(); if (!$user->hasRole('admin')) { return response()->json($this->needPermissionsJson, 401); } } $resource = Resource::find($id); if ($resource) { $resource->delete(); return response()->json(['message' => 'Recurso ha sido eliminado']); } else { return response()->json($this->resourceNotFound, 404); } }
/** * Delete a resource. * @param $id * @param \App\Http\Requests\GenericRequest $request * @return mixed */ public function destroy($id, GenericRequest $request) { $request->requireAjax(); $resource = Resource::find($id); if (!$resource) { return $this->ajaxError('Couldn\'t find that resource', 404); } $resource->delete(); if ($resource->isFile()) { File::delete($resource->getFilePath()); } Flash::success('Resource deleted'); return Response::json(true); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { return Resource::find($id); }