public function vote($id, $userVote) { // Make sure the capture is real and the vote is valid $vote = new \App\Vote(); $vote->user_id = \Auth::user()->id; $vote->capture_id = $id; $vote->vote = $userVote == 'up' ? 'true' : 'false'; $vote->save(); $capture = \App\Capture::findOrFail($id); return redirect('pokedex/' . $capture->pokemon->name); }
public function updateCapture(Request $request, $id) { // Validation $this->validate($request, ['pokemon' => 'required|exists:pokemon,id', 'photo' => 'image']); // Get info on the capture $capture = Capture::findOrFail($id); // Only run if the using attempts to upload a new photo if ($request->hasFile('photo')) { // Generate a new file name $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension(); // Resize the image \Image::make($request->file('photo'))->resize(320, null, function ($constraint) { $constraint->aspectRatio(); })->save('img/captures/' . $fileName); // Delete the old image \File::Delete('img/captures' . $capture->photo); // Make sure the capture is updated with the new file $capture->photo = $fileName; } // Check if the user has provided any changes $capture->save(); // Redirect the user to their captures return redirect('pokecentre/captures'); }
public function doRelease($id) { // Find info on the Pokemon the user wants to release try { $capture = Capture::where('user_id', \Auth::user()->id)->where('id', $id)->firstOrFail(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return view('errors.captureNotFound'); } // Delete the old image \File::Delete('img/captures/' . $capture->photo); \Session::flash('release', 'Bye bye ' . $capture->pokemon->name); Capture::destroy($id); return redirect('pokecentre/captures'); }
public function updateCapture(Request $request, $id) { $this->validate($request, ['pokemon' => 'required|exists:pokemon,id', 'photo' => 'image']); // Get info on the capture $capture = Capture::findOrFail($id); if ($request->hasFile('photo')) { // Generate a new file name $fileName = uniqid() . '.' . $request->file('photo')->getClientOriginalExtension(); \Image::make($request->file('photo'))->resize(320, null, function ($constraint) { $constraint->aspectRatio(); })->save('img/captures/' . $fileName); // Delete the old image \File::Delete('img/captures/' . $capture->photo); $capture->photo = $fileName; } if (\Carbon\Carbon::now()->diffInDays($capture->updated_at) > 5) { if ($capture->attack < 350) { $capture->attack += rand(0, 10); if ($capture->attack > 350) { $capture->attack = 350; } } if ($capture->defense < 350) { $capture->defense += rand(0, 10); if ($capture->defense > 350) { $capture->defense = 350; } } } $capture->pokemon_id = $request->pokemon; $capture->save(); return redirect('pokecentre/captures'); }
/** * save one game. * @param $data * @param $package * @return static * @internal param $item */ protected function saveGames($data, $package) { $data['icon'] = $this->saveImageFromLink($data['icon'], 'avatars'); if ($data['icon']) { $category = Category::where('name', $data['category'])->first(); if (!$category) { copy(public_path() . '/images/avatars/' . $data['icon'], public_path() . '/images/categories/' . $data['icon']); $category = Category::create(['name' => $data['category'], 'icon' => $data['icon'], 'type' => $data['type']]); } $data['category_id'] = $category->id; try { $game = Game::create($data); foreach ($data['screens'] as $urlCapture) { $urlCapture = $this->saveImageFromLink($urlCapture, 'captures'); if ($urlCapture) { Capture::create(['name' => $urlCapture, 'game_id' => $game->id]); } } try { Package::create([ 'game_id' => $game->id, 'name' => $package ]); } catch (QueryException $e) { DB::table('packages')->where('name', $package)->delete(); Package::create([ 'game_id' => $game->id, 'name' => $package ]); } } catch (QueryException $e) { return; } } }