public function edit($plantID, $photoID, $photo) { if ($photo == null) { $fileName = $photoID . '-plant-' . $plantID . '.jpeg'; $deleteRow = 'PlantPictures/' . $plantID . '/' . $fileName; File::delete(public_path() . '/PlantPictures/' . $plantID . '/' . $fileName); $photosRow = Photos::where('photo_url', '=', $deleteRow)->first(); $photosRow->photo_url = 'null'; $photosRow->save(); } else { $fileName = $photoID . "-plant-" . $plantID . ".jpeg"; $photoURL = "PlantPictures" . "/" . $plantID . "/"; $editPhoto = Photos::where('plant_id', '=', $plantID)->get()[$photoID]; $editPhoto->photo_url = $photoURL . $fileName; $editPhoto->save(); $photo->move(public_path() . "/" . "PlantPictures" . "/" . $plantID . "/", $fileName); } }