From a0daf14737e6f470c561ab595332b997eabbcdbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 19 Sep 2022 07:09:47 +0000 Subject: [PATCH] Ticket1001 --- .../Controllers/Bo/SubRangeController.php | 41 ++++++++++++++ ...2_08_31_112505_allow_subrange_deletion.php | 55 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 database/migrations/2022_08_31_112505_allow_subrange_deletion.php diff --git a/app/Http/Controllers/Bo/SubRangeController.php b/app/Http/Controllers/Bo/SubRangeController.php index c88d85cf..823a8a15 100644 --- a/app/Http/Controllers/Bo/SubRangeController.php +++ b/app/Http/Controllers/Bo/SubRangeController.php @@ -10,17 +10,33 @@ use Illuminate\Support\Facades\File; class SubRangeController extends Controller { + /** + * Viewany subrange + * + * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory + */ public function index() { $subranges = SubRange::paginate(); return view('bo.subranges.index', compact('subranges')); } + /** + * Create subrange + * + * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory + */ public function create() { return view('bo.subranges.create'); } + /** + * Store subrange + * + * @param \App\Http\Requests\StoreSubRange $request + * @return \Illuminate\Http\RedirectResponse + */ public function store(StoreSubRange $request) { $subrange = new SubRange($request->validated()); @@ -29,11 +45,24 @@ class SubRangeController extends Controller 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()); @@ -43,6 +72,12 @@ class SubRangeController extends Controller ->with('success', 'Enregistré !'); } + /** + * Destroy subrange + * + * @param \App\Models\SubRange $subrange + * @return \Illuminate\Http\RedirectResponse + */ public function destroy(SubRange $subrange) { if (File::exists($subrange->picture)) { @@ -57,6 +92,12 @@ class SubRangeController extends Controller ->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)) { diff --git a/database/migrations/2022_08_31_112505_allow_subrange_deletion.php b/database/migrations/2022_08_31_112505_allow_subrange_deletion.php new file mode 100644 index 00000000..48c18eee --- /dev/null +++ b/database/migrations/2022_08_31_112505_allow_subrange_deletion.php @@ -0,0 +1,55 @@ +dropForeign('range_sub_range_range_id_foreign'); + $table->foreign('range_id') + ->references('id')->on('ranges') + ->cascadeOnDelete(); + $table->dropForeign('range_sub_range_sub_range_id_foreign'); + $table->foreign('sub_range_id') + ->references('id')->on('sub_ranges') + ->cascadeOnDelete(); + }); + Schema::table('products', function (Blueprint $table) { + $table->dropForeign('products_sub_range_id_foreign'); + $table->foreign('sub_range_id') + ->references('id')->on('sub_ranges') + ->nullOnDelete(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('range_sub_range', function (Blueprint $table) { + $table->dropForeign('range_sub_range_range_id_foreign'); + $table->foreign('range_id') + ->references('id')->on('ranges'); + $table->dropForeign('range_sub_range_sub_range_id_foreign'); + $table->foreign('sub_range_id') + ->references('id')->on('sub_ranges'); + }); + Schema::table('products', function (Blueprint $table) { + $table->dropForeign('products_sub_range_id_foreign'); + $table->foreign('sub_range_id') + ->references('id')->on('sub_ranges'); + }); + } +}