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'); }
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'); }