70 lines
2 KiB
PHP
70 lines
2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Bo;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\StoreSubRange;
|
|
use App\Http\Requests\UpdateSubRange;
|
|
use App\Models\SubRange;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class SubRangeController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$subranges = SubRange::paginate();
|
|
return view('bo.subranges.index', compact('subranges'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('bo.subranges.create');
|
|
}
|
|
|
|
public function store(StoreSubRange $request)
|
|
{
|
|
$subrange = new SubRange($request->validated());
|
|
$this->storeUploadedImage($request, $subrange, 'picture');
|
|
$subrange->saveOrFail();
|
|
return redirect()->route('bo.subranges.index');
|
|
}
|
|
|
|
public function edit(SubRange $subrange)
|
|
{
|
|
return view('bo.subranges.edit', ['subrange' => $subrange]);
|
|
}
|
|
|
|
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é !');
|
|
}
|
|
|
|
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é');
|
|
}
|
|
|
|
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 !');
|
|
}
|
|
}
|