validated()); $this->storeUploadedImage($request, $subrange, 'picture'); $subrange->saveOrFail(); return redirect()->route('bo.subranges.index'); } /** * Edit subrange * * @param \App\Models\SubRange $subrange * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory */ public function edit(SubRange $subrange) { return view('bo.subranges.edit', ['subrange' => $subrange]); } /** * Update subrange * * @param \App\Http\Requests\UpdateSubRange $request * @param \App\Models\SubRange $subrange * @return \Illuminate\Http\RedirectResponse */ public function update(UpdateSubRange $request, SubRange $subrange) { $subrange->fill($request->validated()); $this->storeUploadedImage($request, $subrange, 'picture'); $subrange->saveOrFail(); return redirect()->route('bo.subranges.edit', $subrange) ->with('success', 'Enregistré !'); } /** * Destroy subrange * * @param \App\Models\SubRange $subrange * @return \Illuminate\Http\RedirectResponse */ public function destroy(SubRange $subrange) { if (File::exists($subrange->picture)) { File::delete($subrange->picture); } if (!$subrange->delete()) { return redirect()->route('bo.subranges.index') ->with('error', 'Le contenu n\'a pas pu être supprimé'); } return redirect()->route('bo.subranges.index') ->with('warning', 'Le contenu a bien été supprimé'); } /** * Remove subrange picture * * @param \App\Models\SubRange $subrange * @return \Illuminate\Http\RedirectResponse */ public function removeImage(SubRange $subrange) { if (File::exists($subrange->picture)) { File::delete($subrange->picture); } $subrange->picture = ''; $subrange->saveOrFail(); return redirect()->route('bo.subranges.edit', $subrange) ->with('warning', 'L\'image à bien été supprimée !'); } }