Merge branch 'ticket1001' into 'develop'

Ticket1001

See merge request service-web-lab/le-gaulois!23
This commit is contained in:
Vincent BRIDIER 2022-09-19 07:09:47 +00:00
commit b46aa0b60e
2 changed files with 96 additions and 0 deletions

View file

@ -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)) {

View file

@ -0,0 +1,55 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AllowSubrangeDeletion extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('range_sub_range', function (Blueprint $table) {
$table->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');
});
}
}