From 2648256177280071632ded34daa606a456557bc9 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 6 Nov 2023 11:13:14 +0100 Subject: [PATCH] update bo conviction: remove index page and redirect to the edit --- .../Bo/ConvictionpageController.php | 59 ++++++----------- app/Policies/ConvictionpagePolicy.php | 11 ---- resources/views/bo/layouts/nav-list.blade.php | 2 +- .../bo/pages/convictionpages/edit.blade.php | 17 ++--- .../convictionpages/index-list.blade.php | 63 ------------------- .../bo/pages/convictionpages/index.blade.php | 16 ----- routes/breadcrumbs-bo.php | 10 +-- routes/web-bo.php | 5 +- 8 files changed, 32 insertions(+), 151 deletions(-) delete mode 100644 resources/views/bo/pages/convictionpages/index-list.blade.php delete mode 100644 resources/views/bo/pages/convictionpages/index.blade.php diff --git a/app/Http/Controllers/Bo/ConvictionpageController.php b/app/Http/Controllers/Bo/ConvictionpageController.php index 445827c..dd582c6 100644 --- a/app/Http/Controllers/Bo/ConvictionpageController.php +++ b/app/Http/Controllers/Bo/ConvictionpageController.php @@ -10,65 +10,44 @@ use Illuminate\Support\Str; class ConvictionpageController extends Controller { - /** - * Create the controller instance. - */ - public function __construct() - { - $this->authorizeResource(Convictionpage::class); - } - - /** - * Display a listing of the resource. - * - * @return \Illuminate\Contracts\View\View - */ - public function index(): \Illuminate\Contracts\View\View - { - /** @var \Illuminate\Database\Eloquent\Builder $convictionpageModels */ - $convictionpageModels = Convictionpage::query(); - - /** Sort columns with a query */ - $this->sortQuery($convictionpageModels); - - /** Custom pagination */ - $convictionpageModels = $this->paginate($convictionpageModels); - - return view('bo.pages.convictionpages.index', compact('convictionpageModels')); - } - /** * Show the form for editing the specified resource. * - * @param App\Models\Convictionpage $convictionpage * @return \Illuminate\Contracts\View\View */ - public function edit(Convictionpage $convictionpage): \Illuminate\Contracts\View\View + public function edit(): \Illuminate\Contracts\View\View { - return view('bo.pages.convictionpages.edit', ['convictionpageModel' => $convictionpage]); + $this->authorize('update', \App\Models\Convictionpage::class); + + /** @var \App\Models\Convictionpage $convictionpageModel */ + $convictionpageModel = Convictionpage::query()->firstOrFail(); + + return view('bo.pages.convictionpages.edit', compact('convictionpageModel')); } /** * Update the specified resource in storage. * * @param \App\Http\Requests\Bo\Convictionpages\UpdateConvictionpageRequest $request - * @param \App\Models\Convictionpage $convictionpage * @return \Illuminate\Http\RedirectResponse */ - public function update( - UpdateConvictionpageRequest $request, - Convictionpage $convictionpage - ): \Illuminate\Http\RedirectResponse { - return DB::transaction(function () use ($request, $convictionpage) { - $convictionpage->fill($request->validated()); + public function update(UpdateConvictionpageRequest $request): \Illuminate\Http\RedirectResponse + { + $this->authorize('update', \App\Models\Convictionpage::class); - if ($convictionpage->saveOrFail()) { - return redirect()->route('bo.convictionpages.edit', $convictionpage) + return DB::transaction(function () use ($request) { + /** @var \App\Models\Convictionpage $convictionpageModel */ + $convictionpageModel = Convictionpage::query()->firstOrFail(); + + $convictionpageModel->fill($request->validated()); + + if ($convictionpageModel->saveOrFail()) { + return redirect()->route('bo.convictionpages.edit') ->with('success', __('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(__('models.classes.convictionpage')) ])); } - return redirect()->route('bo.convictionpages.edit', $convictionpage) + return redirect()->route('bo.convictionpages.edit') ->with('error', __('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(__('models.classes.convictionpage')) ])); diff --git a/app/Policies/ConvictionpagePolicy.php b/app/Policies/ConvictionpagePolicy.php index 48c4ce7..03a8c05 100644 --- a/app/Policies/ConvictionpagePolicy.php +++ b/app/Policies/ConvictionpagePolicy.php @@ -19,17 +19,6 @@ class ConvictionpagePolicy return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); } - /** - * Determine whether the user can view the model. - * - * @param \App\Models\User $authUser - * @return boolean - */ - public function view(User $authUser): bool - { - return UserStaticRules::atLeastRole($authUser, RoleEnum::admin); - } - /** * Determine whether the user can update the model. * diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index 8dfe276..6c17a05 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -92,7 +92,7 @@ @can('viewAny', \App\Models\Convictionpage::class)
  • {{ Str::of(__('models.classes.convictionpage'))->ucfirst() }} diff --git a/resources/views/bo/pages/convictionpages/edit.blade.php b/resources/views/bo/pages/convictionpages/edit.blade.php index ad47ec2..c236587 100644 --- a/resources/views/bo/pages/convictionpages/edit.blade.php +++ b/resources/views/bo/pages/convictionpages/edit.blade.php @@ -8,23 +8,16 @@ @section('content')
    - - - @include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $convictionpageModel])
    -
    - -
    +
    -
    + @csrf @method('PUT') @include('bo.pages.convictionpages.form') diff --git a/resources/views/bo/pages/convictionpages/index-list.blade.php b/resources/views/bo/pages/convictionpages/index-list.blade.php deleted file mode 100644 index 144fca7..0000000 --- a/resources/views/bo/pages/convictionpages/index-list.blade.php +++ /dev/null @@ -1,63 +0,0 @@ - - @if (count($convictionpageModels) > 0) - - @include('bo.modules.table-col-sorter', [ - 'cols' => [ - 'key_feed' => Str::ucfirst(__('validation.custom.key_feed')), - 'key_earth_1' => Str::ucfirst(__('validation.custom.key_earth_1')), - 'key_earth_2' => Str::ucfirst(__('validation.custom.key_earth_2')), - 'key_together_1' => Str::ucfirst(__('validation.custom.key_together_1')), - 'key_together_2' => Str::ucfirst(__('validation.custom.key_together_2')), - 'key_together_3' => Str::ucfirst(__('validation.custom.key_together_3')), - 'key_together_4' => Str::ucfirst(__('validation.custom.key_together_4')), - 'key_territory' => Str::ucfirst(__('validation.custom.key_territory')), - 'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')), - ], - ]) - - - @foreach ($convictionpageModels as $convictionpageModel) - - - - - - - - - - - @php - $routeName = request() - ->route() - ->getName(); - @endphp - - - @endforeach - - @else - - - - @endif -
    {{ $convictionpageModel->key_feed }}{{ $convictionpageModel->key_earth_1 }}{{ $convictionpageModel->key_earth_2 }}{{ $convictionpageModel->key_together_1 }}{{ $convictionpageModel->key_together_2 }}{{ $convictionpageModel->key_together_3 }}{{ $convictionpageModel->key_together_4 }}{{ $convictionpageModel->key_territory }} - {{ $convictionpageModel->updated_at->isoFormat('LLLL') }} - - @canAny(['update'], $convictionpageModel) - - @can('update', $convictionpageModel) - - - - @endcan - - @else - - - - @endcan -
    {{ __('crud.other.no_model_found', ['model' => __('models.classes.convictionpage')]) }}
    diff --git a/resources/views/bo/pages/convictionpages/index.blade.php b/resources/views/bo/pages/convictionpages/index.blade.php deleted file mode 100644 index abad237..0000000 --- a/resources/views/bo/pages/convictionpages/index.blade.php +++ /dev/null @@ -1,16 +0,0 @@ -@extends('bo.layout') - -@section('title', - Str::of(__('models.classes.convictionpage'))->plural()->ucfirst()) -@section('description', trans_choice('crud.meta.description.index', 0, ['model' => Str::plural(__('models.classes.convictionpage'))])) - -@section('content') -
    - @include('modules.breadcrumbs.breadcrumb-body') -
    - -
    - @include('bo.pages.convictionpages.index-list') -
    - {{ $convictionpageModels->links() }} -@endsection diff --git a/routes/breadcrumbs-bo.php b/routes/breadcrumbs-bo.php index 3128ef5..eb3fa0c 100644 --- a/routes/breadcrumbs-bo.php +++ b/routes/breadcrumbs-bo.php @@ -2,7 +2,6 @@ use App\Models\ActivityLog; use App\Models\Commitment; -use App\Models\Convictionpage; use App\Models\Joinuspage; use App\Models\Range; use App\Models\News; @@ -212,14 +211,11 @@ Breadcrumbs::for('bo.products.duplicate', function (Generator $trail) { // * CONVICTIONPAGES Breadcrumbs::for('bo.convictionpages.index', function (Generator $trail) { - $trail->push( - Str::of(trans('models.classes.convictionpage'))->plural()->ucfirst(), - route('bo.convictionpages.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc']) - ); + $trail->push(Str::ucfirst(trans('models.classes.explorerpage'))); }); -Breadcrumbs::for('bo.convictionpages.edit', function (Generator $trail, Convictionpage $convictionpage) { +Breadcrumbs::for('bo.convictionpages.edit', function (Generator $trail) { $trail->parent('bo.convictionpages.index'); - $trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.convictionpages.edit', $convictionpage)); + $trail->push(Str::ucfirst(trans('crud.actions.edit'))); }); // * TESTIMONIALS diff --git a/routes/web-bo.php b/routes/web-bo.php index c719e6b..35ecd66 100644 --- a/routes/web-bo.php +++ b/routes/web-bo.php @@ -153,7 +153,10 @@ Route::prefix('bo') ])->name('products.duplicate'); // * CONVICTIONPAGES - Route::resource('convictionpages', ConvictionpageController::class)->only(['index', 'edit', 'update']); + Route::get('/convictionpages/edit', [ConvictionpageController::class, 'edit']) + ->name('convictionpages.edit'); + Route::put('/convictionpages/update', [ConvictionpageController::class, 'update']) + ->name('convictionpages.update'); // * JOINUSPAGES Route::resource('joinuspages', JoinuspageController::class)->only(['index', 'edit', 'update']);