update bo explorer: remove index page and redirect to the edit

This commit is contained in:
Alexis Gousseau 2023-11-06 11:04:33 +01:00
parent 35f6d98dbc
commit 5f90384be4
10 changed files with 49 additions and 192 deletions

View file

@ -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<array-key, \App\Models\Commitment> */
$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'))
]));

View file

@ -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.
*

View file

@ -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.
*

View file

@ -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(),
];
}

View file

@ -83,7 +83,7 @@
@can('viewAny', \App\Models\Explorerpage::class)
<li>
<a class="nav-link @if (request()->routeIs('bo.explorerpages.*')) active @endif" data-bs-toggle="tooltip"
href="{{ route('bo.explorerpages.index') }}"
href="{{ route('bo.explorerpages.edit') }}"
title="{{ trans_choice('crud.meta.title.edit', 1, ['model' => __('models.classes.explorerpage')]) }}">
{{ Str::of(__('models.classes.explorerpage'))->ucfirst() }}
</a>

View file

@ -8,22 +8,16 @@
@section('content')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap pb-3">
<div class="d-flex align-items-start flex-row">
<a class="btn btn-primary text-decoration-none m-0" data-bs-toggle="tooltip" href="{{ route('bo.explorerpages.index') }}"
title="{{ __('crud.helpers.list_all', ['model' => Str::plural(__('models.classes.explorerpage'))]) }}">
<i class="fa-solid fa-arrow-left"></i>
</a>
@include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $explorerpageModel])
</div>
<div class="mb-md-0 mb-2">
<form class="btn-group confirmDeleteTS" action="{{ route('bo.explorerpages.edit', $explorerpageModel) }}" method="POST" novalidate>
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.explorerpage')]) }}">
{{ Str::ucfirst(__('crud.actions.save')) }}
</button>
</form>
<button class="btn btn-primary" id="formSubmitClone" data-bs-toggle="tooltip" type="submit"
title="{{ __('crud.helpers.save_model', ['model' => __('models.classes.explorerpage')]) }}">
{{ Str::ucfirst(__('crud.actions.save')) }}
</button>
</div>
</div>
<form action="{{ route('bo.explorerpages.update', $explorerpageModel) }}" method="POST" enctype="multipart/form-data">
<form action="{{ route('bo.explorerpages.update') }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')
@include('bo.pages.explorerpages.form')

View file

@ -1,68 +0,0 @@
<table class="table-hover table-fix-action m-0 table">
@if (count($explorerpageModels) > 0)
<thead>
@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')),
],
])
</thead>
<tbody>
@foreach ($explorerpageModels as $explorerpageModel)
<tr class="border-bottom list-item">
<td class="text-center align-middle">
<img src="{{ asset($explorerpageModel->picture_1) }}" title="{{ $explorerpageModel->picture_1_title }}"
alt="{{ $explorerpageModel->picture_1_alt }}" height="50px">
</td>
<td class="text-center align-middle">{{ $explorerpageModel->picture_1_title }}1</td>
<td class="text-center align-middle">
<img src="{{ asset($explorerpageModel->picture_2) }}" title="{{ $explorerpageModel->picture_2_title }}"
alt="{{ $explorerpageModel->picture_2_alt }}" height="50px">
</td>
<td class="text-center align-middle">{{ $explorerpageModel->picture_2_title }}2</td>
<td class="text-center align-middle">
<img src="{{ asset($explorerpageModel->picture_3) }}" title="{{ $explorerpageModel->picture_3_title }}"
alt="{{ $explorerpageModel->picture_3_alt }}" height="50px">
</td>
<td class="text-center align-middle">{{ $explorerpageModel->picture_3_title }}</td>
<td class="text-center align-middle">
<span class="badge bg-secondary">{{ $explorerpageModel->updated_at->isoFormat('LLLL') }}</span>
</td>
@php
$routeName = request()
->route()
->getName();
@endphp
<td class="text-end align-middle">
@canAny(['update'], $explorerpageModel)
<form class="btn-group confirmDeleteTS" action="{{ route('bo.explorerpages.edit', $explorerpageModel) }}"
method="POST" novalidate>
@can('update', $explorerpageModel)
<a class="btn btn-sm btn-primary" data-bs-toggle="tooltip"
href="{{ route('bo.explorerpages.edit', ['explorerpage' => $explorerpageModel]) }}"
title="{{ Str::ucfirst(__('crud.actions.update')) }}">
<i class="fa-solid fa-pencil"></i>
</a>
@endcan
</form>
@else
<span class="text-danger" data-bs-toggle="tooltip" title="{{ __('list.right') }}">
<i class="fa-solid fa-ban"></i>
</span>
@endcan
</td>
</tr>
@endforeach
</tbody>
@else
<tr>
<td class="border-0">{{ __('crud.other.no_model_found', ['model' => __('models.classes.explorerpage')]) }}</td>
</tr>
@endif
</table>

View file

@ -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')
<div class="d-flex justify-content-between flex-md-nowrap align-items-center flex-wrap">
@include('modules.breadcrumbs.breadcrumb-body')
</div>
@include('bo.modules.search-bar')
<div class="table-responsive mb-3">
@include('bo.pages.explorerpages.index-list')
</div>
{{ $explorerpageModels->links() }}
@endsection

View file

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

View file

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