diff --git a/app/Http/Controllers/Bo/ExplorerpageController.php b/app/Http/Controllers/Bo/ExplorerpageController.php index 519a6af..f6cc2e3 100644 --- a/app/Http/Controllers/Bo/ExplorerpageController.php +++ b/app/Http/Controllers/Bo/ExplorerpageController.php @@ -6,94 +6,53 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest; use App\Models\Commitment; use App\Models\Explorerpage; -use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; class ExplorerpageController extends Controller { - /** - * Create the controller instance. - */ - public function __construct() - { - $this->authorizeResource(Explorerpage::class); - } - - /** - * Display a listing of the resource. - * - * @param \Illuminate\Http\Request $request - * @return \Illuminate\Contracts\View\View - */ - public function index(Request $request): \Illuminate\Contracts\View\View - { - /** @var \Illuminate\Database\Eloquent\Builder $explorerpageModels */ - $explorerpageModels = Explorerpage::query(); - - /** @var string $search Search field */ - $search = $request->search; - if ($search) { - $this->searchQuery( - $explorerpageModels, - $search, - null, - 'picture_1_title', - 'picture_2_title', - 'picture_3_title' - ); - } - $searchFields = \implode(', ', [ - Str::ucfirst(trans('validation.attributes.title')) - ]); - - /** Sort columns with a query */ - $this->sortQuery($explorerpageModels); - - /** Custom pagination */ - $explorerpageModels = $this->paginate($explorerpageModels); - - return view('bo.pages.explorerpages.index', compact('explorerpageModels', 'search', 'searchFields')); - } - /** * Show the form for editing the specified resource. * - * @param App\Models\Explorerpage $explorerpage * @return \Illuminate\Contracts\View\View */ - public function edit(Explorerpage $explorerpage): \Illuminate\Contracts\View\View + public function edit(): \Illuminate\Contracts\View\View { + $this->authorize('update', \App\Models\Explorerpage::class); + + /** @var \App\Models\Explorerpage $explorerpageModel */ + $explorerpageModel = Explorerpage::query()->firstOrFail(); + + /** @var \Illuminate\Database\Eloquent\Collection */ $commitmentModels = Commitment::all(); - return view('bo.pages.explorerpages.edit', [ - 'explorerpageModel' => $explorerpage, - 'commitmentModels' => $commitmentModels, - ]); + return view('bo.pages.explorerpages.edit', compact('explorerpageModel', 'commitmentModels')); } /** * Update the specified resource in storage. * - * @param \App\Http\Requests\Bo\Explorerpages\UpdateExplorerpageRequest $request - * @param \App\Models\Explorerpage $explorerpage + * @param \App\Http\Requests\Bo\Explorerpage\UpdateExplorerpageRequest $request * @return \Illuminate\Http\RedirectResponse */ - public function update( - UpdateExplorerpageRequest $request, - Explorerpage $explorerpage - ): \Illuminate\Http\RedirectResponse { - return DB::transaction(function () use ($request, $explorerpage) { - $explorerpage->fill($request->safe()->except('commitments')); - $explorerpage->commitments()->sync(\collect($request->validated('commitments'))->pluck('id')); + public function update(UpdateExplorerpageRequest $request): \Illuminate\Http\RedirectResponse + { + $this->authorize('update', \App\Models\Explorerpage::class); - if ($explorerpage->saveOrFail()) { - return redirect()->route('bo.explorerpages.edit', $explorerpage) + return DB::transaction(function () use ($request) { + /** @var \App\Models\Explorerpage $explorerpageModel */ + $explorerpageModel = Explorerpage::query()->firstOrFail(); + + $explorerpageModel->fill($request->safe()->except('commitments')); + $explorerpageModel->commitments()->sync(\collect($request->validated('commitments'))->pluck('id')); + + if ($explorerpageModel->saveOrFail()) { + return redirect()->route('bo.explorerpages.edit') ->with('success', __('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(__('models.classes.explorerpage')) ])); } - return redirect()->route('bo.explorerpages.edit', $explorerpage) + return redirect()->route('bo.explorerpages.edit') ->with('error', __('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(__('models.classes.explorerpage')) ])); diff --git a/app/Models/Explorerpage.php b/app/Models/Explorerpage.php index a767d5b..c6dec15 100644 --- a/app/Models/Explorerpage.php +++ b/app/Models/Explorerpage.php @@ -8,15 +8,15 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** - * @property string $picture_1 Chiffre clé 'bien nourrir'. - * @property string $picture_1_alt Chiffre clé 'bien nourrir'. - * @property string $picture_1_title Chiffre clé 'bien nourrir'. - * @property string $picture_2 Chiffre clé 'bien nourrir'. - * @property string $picture_2_alt Chiffre clé 'bien nourrir'. - * @property string $picture_2_title Chiffre clé 'bien nourrir'. - * @property string $picture_3 Chiffre clé 'bien nourrir'. - * @property string $picture_3_alt Chiffre clé 'bien nourrir'. - * @property string $picture_3_title Chiffre clé 'bien nourrir'. + * @property string $picture_1 Path de l'image n°1 explorateur. + * @property string $picture_1_alt Attribut alt de l'image n°1 explorateur. + * @property string $picture_1_title Attribut title de l'image n°1 explorateur. + * @property string $picture_2 Path de l'image n°2 explorateur. + * @property string $picture_2_alt Attribut alt de l'image n°2 explorateur. + * @property string $picture_2_title Attribut title de l'image n°2 explorateur. + * @property string $picture_3 Path de l'image n°3 explorateur. + * @property string $picture_3_alt Attribut alt de l'image n°3 explorateur. + * @property string $picture_3_title Attribut title de l'image n°3 explorateur. * @property-read \Carbon\Carbon $created_at Created date. * @property-read \Carbon\Carbon $updated_at Updated date. * diff --git a/app/Policies/ExplorerpagePolicy.php b/app/Policies/ExplorerpagePolicy.php index e7e05d7..7b9a39c 100644 --- a/app/Policies/ExplorerpagePolicy.php +++ b/app/Policies/ExplorerpagePolicy.php @@ -19,17 +19,6 @@ class ExplorerpagePolicy 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/database/factories/ExplorerpageFactory.php b/database/factories/ExplorerpageFactory.php index 09ba213..bc2df08 100644 --- a/database/factories/ExplorerpageFactory.php +++ b/database/factories/ExplorerpageFactory.php @@ -14,11 +14,11 @@ class ExplorerpageFactory extends Factory public function definition() { return [ - 'picture_1_alt' => fake()->sentence(), + 'picture_1_alt' => fake()->sentence(), 'picture_1_title' => fake()->sentence(), - 'picture_2_alt' => fake()->sentence(), + 'picture_2_alt' => fake()->sentence(), 'picture_2_title' => fake()->sentence(), - 'picture_3_alt' => fake()->sentence(), + 'picture_3_alt' => fake()->sentence(), 'picture_3_title' => fake()->sentence(), ]; } diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php index 978a22e..8dfe276 100644 --- a/resources/views/bo/layouts/nav-list.blade.php +++ b/resources/views/bo/layouts/nav-list.blade.php @@ -83,7 +83,7 @@ @can('viewAny', \App\Models\Explorerpage::class)
  • {{ Str::of(__('models.classes.explorerpage'))->ucfirst() }} diff --git a/resources/views/bo/pages/explorerpages/edit.blade.php b/resources/views/bo/pages/explorerpages/edit.blade.php index 4e75c14..3c24e23 100644 --- a/resources/views/bo/pages/explorerpages/edit.blade.php +++ b/resources/views/bo/pages/explorerpages/edit.blade.php @@ -8,22 +8,16 @@ @section('content')
    - - - @include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $explorerpageModel])
    -
    - -
    +
    -
    + @csrf @method('PUT') @include('bo.pages.explorerpages.form') diff --git a/resources/views/bo/pages/explorerpages/index-list.blade.php b/resources/views/bo/pages/explorerpages/index-list.blade.php deleted file mode 100644 index a99951e..0000000 --- a/resources/views/bo/pages/explorerpages/index-list.blade.php +++ /dev/null @@ -1,68 +0,0 @@ - - @if (count($explorerpageModels) > 0) - - @include('bo.modules.table-col-sorter', [ - 'cols' => [ - 'picture_1' => Str::ucfirst(__('validation.custom.picture_1')), - 'picture_1_title' => Str::ucfirst(__('validation.attributes.title')), - 'picture_2' => Str::ucfirst(__('validation.custom.picture_2')), - 'picture_2_title' => Str::ucfirst(__('validation.attributes.title')), - 'picture_3' => Str::ucfirst(__('validation.custom.picture_3')), - 'picture_3_title' => Str::ucfirst(__('validation.attributes.title')), - 'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')), - ], - ]) - - - @foreach ($explorerpageModels as $explorerpageModel) - - - - - - - - - @php - $routeName = request() - ->route() - ->getName(); - @endphp - - - @endforeach - - @else - - - - @endif -
    - {{ $explorerpageModel->picture_1_alt }} - {{ $explorerpageModel->picture_1_title }}1 - {{ $explorerpageModel->picture_2_alt }} - {{ $explorerpageModel->picture_2_title }}2 - {{ $explorerpageModel->picture_3_alt }} - {{ $explorerpageModel->picture_3_title }} - {{ $explorerpageModel->updated_at->isoFormat('LLLL') }} - - @canAny(['update'], $explorerpageModel) - - @can('update', $explorerpageModel) - - - - @endcan - - @else - - - - @endcan -
    {{ __('crud.other.no_model_found', ['model' => __('models.classes.explorerpage')]) }}
    diff --git a/resources/views/bo/pages/explorerpages/index.blade.php b/resources/views/bo/pages/explorerpages/index.blade.php deleted file mode 100644 index 1afb8b8..0000000 --- a/resources/views/bo/pages/explorerpages/index.blade.php +++ /dev/null @@ -1,16 +0,0 @@ -@extends('bo.layout') - -@section('title', - Str::of(__('models.classes.explorerpage'))->plural()->ucfirst()) -@section('description', trans_choice('crud.meta.description.index', 0, ['model' => Str::plural(__('models.classes.explorerpage'))])) - -@section('content') -
    - @include('modules.breadcrumbs.breadcrumb-body') -
    - @include('bo.modules.search-bar') -
    - @include('bo.pages.explorerpages.index-list') -
    - {{ $explorerpageModels->links() }} -@endsection diff --git a/routes/breadcrumbs-bo.php b/routes/breadcrumbs-bo.php index 7107631..3128ef5 100644 --- a/routes/breadcrumbs-bo.php +++ b/routes/breadcrumbs-bo.php @@ -3,7 +3,6 @@ use App\Models\ActivityLog; use App\Models\Commitment; use App\Models\Convictionpage; -use App\Models\Explorerpage; use App\Models\Joinuspage; use App\Models\Range; use App\Models\News; @@ -162,16 +161,13 @@ Breadcrumbs::for('bo.joinuspages.edit', function (Generator $trail, Joinuspage $ $trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.joinuspages.edit', $joinuspage)); }); -// * EXPLORERPAGES +// * EXPLORERPAGE Breadcrumbs::for('bo.explorerpages.index', function (Generator $trail) { - $trail->push( - Str::of(trans('models.classes.explorerpage'))->plural()->ucfirst(), - route('bo.explorerpages.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc']) - ); + $trail->push(Str::ucfirst(trans('models.classes.explorerpage'))); }); -Breadcrumbs::for('bo.explorerpages.edit', function (Generator $trail, Explorerpage $explorerpage) { +Breadcrumbs::for('bo.explorerpages.edit', function (Generator $trail) { $trail->parent('bo.explorerpages.index'); - $trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.explorerpages.edit', $explorerpage)); + $trail->push(Str::ucfirst(trans('crud.actions.edit'))); }); // * STAMPS diff --git a/routes/web-bo.php b/routes/web-bo.php index 75a7f1b..c719e6b 100644 --- a/routes/web-bo.php +++ b/routes/web-bo.php @@ -132,8 +132,11 @@ Route::prefix('bo') StampController::class, 'duplicate' ])->name('stamps.duplicate'); - // * EXPLORERPAGE - Route::resource('explorerpages', ExplorerpageController::class)->only(['index', 'edit', 'update']); + // * EXPLORERPAGES + Route::get('/explorerpages/edit', [ExplorerpageController::class, 'edit']) + ->name('explorerpages.edit'); + Route::put('/explorerpages/update', [ExplorerpageController::class, 'update']) + ->name('explorerpages.update'); // * PRODUCTS Route::resource('products', ProductController::class)->except('show')