diff --git a/app/Http/Controllers/Bo/SeasonalSectionController.php b/app/Http/Controllers/Bo/SeasonalSectionController.php
new file mode 100644
index 0000000..66d1240
--- /dev/null
+++ b/app/Http/Controllers/Bo/SeasonalSectionController.php
@@ -0,0 +1,167 @@
+authorizeResource(SeasonalSection::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 $seasonalSectionModels */
+ $seasonalSectionModels = SeasonalSection::query();
+
+ /** @var string $search Search field */
+ $search = $request->search;
+ if ($search) {
+ $this->searchQuery(
+ $seasonalSectionModels,
+ $search,
+ null,
+ 'title',
+ 'text',
+ );
+ }
+ $searchFields = \implode(', ', [
+ Str::ucfirst(trans('validation.attributes.title')),
+ trans('validation.attributes.text'),
+ ]);
+
+ /** Sort columns with a query */
+ $this->sortQuery($seasonalSectionModels);
+
+ /** Custom pagination */
+ $seasonalSectionModels = $this->paginate($seasonalSectionModels);
+
+ return view('bo.pages.seasonal_sections.index', compact('seasonalSectionModels', 'search', 'searchFields'));
+ }
+
+
+ /**
+ * Show the form for creating a new resource.
+ *
+ * @param \App\Models\SeasonalSection $seasonalSection
+ * @return \Illuminate\Contracts\View\View
+ */
+ public function create(SeasonalSection $seasonalSection): \Illuminate\Contracts\View\View
+ {
+ return view('bo.pages.seasonal_sections.create', ['seasonalSectionModel' => $seasonalSection]);
+ }
+
+ /**
+ * Store a newly created resource in storage.
+ *
+ * @param \App\Http\Requests\Bo\SeasonalSections\StoreSeasonalSectionRequest $request
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function store(StoreSeasonalSectionRequest $request): \Illuminate\Http\RedirectResponse
+ {
+ return DB::transaction(function () use ($request) {
+ $seasonalSection = new SeasonalSection();
+ $seasonalSection->fill($request->validated());
+
+ if ($seasonalSection->saveOrFail()) {
+ return redirect()->route('bo.seasonalsections.edit', $seasonalSection)
+ ->with('success', __('crud.messages.has_been_created', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ }
+ return redirect()->back()
+ ->with('error', __('crud.messages.cannot_be_created', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ });
+ }
+
+ /**
+ * Show the form for editing the specified resource.
+ *
+ * @param App\Models\SeasonalSection $seasonalSection
+ * @return \Illuminate\Contracts\View\View
+ */
+ public function edit(SeasonalSection $seasonalSection): \Illuminate\Contracts\View\View
+ {
+ return view('bo.pages.seasonal_sections.edit', ['seasonalSectionModel' => $seasonalSection]);
+ }
+
+ /**
+ * Update the specified resource in storage.
+ *
+ * @param \App\Http\Requests\Bo\SeasonalSections\UpdateSeasonalSectionRequest $request
+ * @param \App\Models\SeasonalSection $seasonalSection
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function update(
+ UpdateSeasonalSectionRequest $request,
+ SeasonalSection $seasonalSection
+ ): \Illuminate\Http\RedirectResponse {
+ return DB::transaction(function () use ($request, $seasonalSection) {
+ $seasonalSection->fill($request->validated());
+
+ if ($seasonalSection->saveOrFail()) {
+ return redirect()->route('bo.seasonalsections.edit', $seasonalSection)
+ ->with('success', __('crud.messages.has_been_updated', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ }
+ return redirect()->route('bo.seasonalsections.edit', $seasonalSection)
+ ->with('error', __('crud.messages.cannot_be_updated', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ });
+ }
+
+ /**
+ * Remove the specified resource from storage.
+ *
+ * @param \App\Models\SeasonalSection $seasonalSection
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function destroy(SeasonalSection $seasonalSection): \Illuminate\Http\RedirectResponse
+ {
+ if ($seasonalSection->deleteOrFail()) {
+ return redirect()->route('bo.seasonalsections.index')
+ ->with('success', __('crud.messages.has_been_deleted', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ }
+ return redirect()->back()
+ ->with('error', __('crud.messages.cannot_be_deleted', [
+ 'model' => Str::ucfirst(trans_choice('models.classes.seasonal_section', 1))
+ ]));
+ }
+
+ /**
+ * Duplicate the specified resource.
+ *
+ * @param \App\Models\SeasonalSection $seasonalSection
+ * @return \Illuminate\Contracts\View\View
+ */
+ public function duplicate(SeasonalSection $seasonalSection): \Illuminate\Contracts\View\View
+ {
+ return $this->create($seasonalSection->replicate());
+ }
+}
diff --git a/app/Http/Requests/Bo/SeasonalSections/StoreSeasonalSectionRequest.php b/app/Http/Requests/Bo/SeasonalSections/StoreSeasonalSectionRequest.php
new file mode 100644
index 0000000..7c46cba
--- /dev/null
+++ b/app/Http/Requests/Bo/SeasonalSections/StoreSeasonalSectionRequest.php
@@ -0,0 +1,80 @@
+check();
+ }
+
+ /**
+ * Prepare the data for validation.
+ *
+ * @return void
+ */
+ protected function prepareForValidation()
+ {
+ $this->merge([
+ 'published' => $this->published ? true : false
+ ]);
+ $this->mergePicture('picture');
+ }
+
+ /**
+ * Get the validation rules that apply to the request.
+ *
+ * @return array
+ */
+ public function rules(): array
+ {
+ $rules = [
+ 'title' => 'required|string|between:3,100',
+ 'text' => 'required|string|min:15',
+ 'picture_alt' => 'required|string|between:3,255',
+ 'picture_title' => 'required|string|between:3,255',
+ 'background' => ['required', new Enum(BackgroundEnum::class)],
+ 'published' => 'required|boolean',
+ 'publish_at' => 'nullable|date',
+ 'unpublish_at' => 'nullable|date|after:publish_at',
+
+ ];
+ return \array_merge(
+ $rules,
+ $this->pictureRules('picture', 362, 542, 362, 542, false),
+ );
+ }
+
+ /**
+ * Get custom attributes for validator errors.
+ *
+ * @return array
+ */
+ public function attributes(): array
+ {
+ return [
+ 'title' => trans('validation.attributes.title'),
+ 'text' => trans('validation.attributes.content'),
+ 'picture_alt' => trans('validation.custom.picture_alt'),
+ 'picture_title' => trans('validation.custom.picture_title'),
+ 'background' => trans('validation.custom.background'),
+ 'published' => trans('validation.custom.activated'),
+ 'publish_at' => trans('validation.custom.publish_at'),
+ 'unpublish_at' => trans('validation.custom.unpublish_at'),
+
+ ];
+ }
+}
diff --git a/app/Http/Requests/Bo/SeasonalSections/UpdateSeasonalSectionRequest.php b/app/Http/Requests/Bo/SeasonalSections/UpdateSeasonalSectionRequest.php
new file mode 100644
index 0000000..a8fc285
--- /dev/null
+++ b/app/Http/Requests/Bo/SeasonalSections/UpdateSeasonalSectionRequest.php
@@ -0,0 +1,7 @@
+ fake()->sentence(),
- 'text' => fake()->text(),
+ 'text' => \clean(\fake()->randomHtml(6, 7)),
'picture_alt' => fake()->sentence(),
'picture_title' => fake()->sentence(),
'published' => false,
diff --git a/database/seeders/SeasonalSectionSeeder.php b/database/seeders/SeasonalSectionSeeder.php
index 09f0f73..6a89aff 100644
--- a/database/seeders/SeasonalSectionSeeder.php
+++ b/database/seeders/SeasonalSectionSeeder.php
@@ -20,15 +20,21 @@ class SeasonalSectionSeeder extends Seeder
$publish_at = now()->subDays(rand(1, 10));
$unpublish_at = $publish_at->copy()->addDays(rand(10, 20));
foreach (BackgroundEnum::cases() as $i => $background) {
- SeasonalSection::factory(1)->create([
- 'background' => $background,
- 'published' => $i === array_key_first(BackgroundEnum::cases()) ? true : false,
- 'publish_at' => $publish_at->subMonths(),
- 'unpublish_at' => $unpublish_at->subMonths(),
- 'picture' => FileStorageHelper::storeFile(new SeasonalSection(), new \SplFileInfo(
- \resource_path('../database/factories/assets/seasonalsections/default-picture-362x542.png')
- )),
- ]);
+ SeasonalSection::factory(1)->make()->each(
+ function (SeasonalSection $seasonalSection) use ($background, $i, $publish_at, $unpublish_at) {
+ $seasonalSection->background = $background;
+ $seasonalSection->published = $i === array_key_first(BackgroundEnum::cases()) ? true : false;
+ $seasonalSection->publish_at = $publish_at->subMonths();
+ $seasonalSection->unpublish_at = $unpublish_at->subMonths();
+ $seasonalSection->picture = FileStorageHelper::storeFile(
+ new SeasonalSection(),
+ new \SplFileInfo(
+ \resource_path('../database/factories/assets/seasonalsections/default-picture-362x542.png')
+ )
+ );
+ $seasonalSection->save();
+ }
+ );
}
}
}
diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php
index 2a77847..f9ad2e7 100644
--- a/resources/lang/en/validation.php
+++ b/resources/lang/en/validation.php
@@ -237,6 +237,6 @@ return [
'attribute_title' => 'title attribute',
'picture_productsheet' => 'productsheet picture',
'picture_thumbnail' => 'thumbnail',
-
+ 'background' => 'background',
],
];
diff --git a/resources/lang/fr/models.php b/resources/lang/fr/models.php
index fa7a7a4..9f3d9a9 100644
--- a/resources/lang/fr/models.php
+++ b/resources/lang/fr/models.php
@@ -2,9 +2,10 @@
return [
'classes' => [
- 'user' => 'utilisateur',
- 'activity_log' => 'journal d\'activité|journaux d\'activité',
- 'static_page' => 'page statique|pages statiques',
- 'range' => 'gamme',
+ 'user' => 'utilisateur',
+ 'activity_log' => 'journal d\'activité|journaux d\'activité',
+ 'static_page' => 'page statique|pages statiques',
+ 'range' => 'gamme',
+ 'seasonal_section' => 'section saisonnière|sections saisonnières',
]
];
diff --git a/resources/lang/fr/validation.php b/resources/lang/fr/validation.php
index 9d94bff..979b969 100644
--- a/resources/lang/fr/validation.php
+++ b/resources/lang/fr/validation.php
@@ -237,6 +237,6 @@ return [
'attribute_title' => 'attribut title',
'picture_productsheet' => 'image de la fiche produit',
'picture_thumbnail' => 'vignette',
-
+ 'background' => 'fond',
],
];
diff --git a/resources/views/bo/layouts/nav-list.blade.php b/resources/views/bo/layouts/nav-list.blade.php
index 77b8032..48b0834 100644
--- a/resources/views/bo/layouts/nav-list.blade.php
+++ b/resources/views/bo/layouts/nav-list.blade.php
@@ -24,6 +24,15 @@
@endcan
+ @can('viewAny', \App\Models\SeasonalSection::class)
+
+
+ {{ Str::title(trans_choice('models.classes.seasonal_section', '*')) }}
+
+
+ @endcan
@canAny(['isConceptor', 'viewAny'], \App\Models\User::class)
diff --git a/resources/views/bo/pages/seasonal_sections/create.blade.php b/resources/views/bo/pages/seasonal_sections/create.blade.php
new file mode 100644
index 0000000..56eb673
--- /dev/null
+++ b/resources/views/bo/pages/seasonal_sections/create.blade.php
@@ -0,0 +1,36 @@
+@extends('bo.layout', ['brParam' => $seasonalSectionModel])
+
+@section('title', __('Création d\'une :model', ['model' => trans_choice('models.classes.seasonal_section', 1)]))
+@section('description', __('Création d\'une toute nouvelle :model', ['model' => trans_choice('models.classes.seasonal_section', 1)]))
+@section('breadcrumb',
+ request()->route()->getName())
+
+@section('content')
+
+
+
+
+
+ @include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $seasonalSectionModel])
+
+
+
+
+
+
+@endsection
diff --git a/resources/views/bo/pages/seasonal_sections/edit.blade.php b/resources/views/bo/pages/seasonal_sections/edit.blade.php
new file mode 100644
index 0000000..ded8336
--- /dev/null
+++ b/resources/views/bo/pages/seasonal_sections/edit.blade.php
@@ -0,0 +1,52 @@
+@extends('bo.layout', ['brParam' => $seasonalSectionModel])
+
+@section('title', __('Édition d\'un :model', ['model' => __('models.classes.seasonal_section')]))
+@section('description', __('Édition d\'un :model déjà existant', ['model' => __('models.classes.seasonal_section')]))
+@section('breadcrumb',
+ request()->route()->getName())
+
+@section('content')
+
+
+
+
+
+ @include('modules.breadcrumbs.breadcrumb-body', ['brParam' => $seasonalSectionModel])
+
+
+
+
+@endsection
diff --git a/resources/views/bo/pages/seasonal_sections/form.blade.php b/resources/views/bo/pages/seasonal_sections/form.blade.php
new file mode 100644
index 0000000..5ef6f92
--- /dev/null
+++ b/resources/views/bo/pages/seasonal_sections/form.blade.php
@@ -0,0 +1,220 @@
+
+ {{-- TITLE --}}
+
+
+
+ {{-- BACKGROUND --}}
+
+
+
+ {{-- TEXT --}}
+
+
+
+ {{-- PICTURE --}}
+
+
+
+ {{-- PUBLISHED --}}
+
+
+
+ {{-- PUBLICATION --}}
+
+
+
+
+
+
+
+
{{ __('* Champs obligatoires') }}
+
+
+
+@push('scripts')
+
+@endpush
diff --git a/resources/views/bo/pages/seasonal_sections/index-list.blade.php b/resources/views/bo/pages/seasonal_sections/index-list.blade.php
new file mode 100644
index 0000000..4b1eeda
--- /dev/null
+++ b/resources/views/bo/pages/seasonal_sections/index-list.blade.php
@@ -0,0 +1,70 @@
+
+ @if (count($seasonalSectionModels) > 0)
+
+ @include('bo.modules.table-col-sorter', [
+ 'cols' => [
+ 'title' => Str::ucfirst(__('validation.attributes.title')),
+ 'background' => Str::ucfirst(__('validation.custom.background')),
+ 'picture' => Str::ucfirst(__('validation.attributes.image')),
+ 'published' => Str::ucfirst(__('validation.custom.activated')),
+ 'updated_at' => Str::ucfirst(__('validation.attributes.updated_at')),
+ ],
+ ])
+
+
+ @foreach ($seasonalSectionModels as $seasonalSectionModel)
+
+ | {{ $seasonalSectionModel->title }} |
+ {{ $seasonalSectionModel->background->label() }} |
+
+
+ |
+ @include('bo.modules.change-published-status', [
+ 'routeName' => 'seasonalsections',
+ 'model' => $seasonalSectionModel,
+ ])
+
+ {{ $seasonalSectionModel->updated_at->isoFormat('LLLL') }}
+ |
+
+ @canAny(['delete', 'duplicate', 'update'], $seasonalSectionModel)
+
+ @else
+
+
+
+ @endcan
+ |
+
+ @endforeach
+
+ @else
+
+ | {{ __('crud.other.no_model_found', ['model' => __('models.classes.seasonal_section')]) }} |
+
+ @endif
+
diff --git a/resources/views/bo/pages/seasonal_sections/index.blade.php b/resources/views/bo/pages/seasonal_sections/index.blade.php
new file mode 100644
index 0000000..2500493
--- /dev/null
+++ b/resources/views/bo/pages/seasonal_sections/index.blade.php
@@ -0,0 +1,21 @@
+@extends('bo.layout')
+
+@section('title', Str::ucfirst(trans_choice('models.classes.seasonal_section', '*')))
+@section('description', __('Liste de tous les :model', ['model' => trans_choice('models.classes.seasonal_section', '*')]))
+
+@section('content')
+
+ @include('modules.breadcrumbs.breadcrumb-body')
+ @can('create', \App\Models\Range::class)
+
+
+
+ @endcan
+
+ @include('bo.modules.search-bar')
+
+ @include('bo.pages.seasonal_sections.index-list')
+
+ {{ $seasonalSectionModels->links() }}
+@endsection
diff --git a/routes/breadcrumbs-bo.php b/routes/breadcrumbs-bo.php
index 1a993c1..db43e50 100644
--- a/routes/breadcrumbs-bo.php
+++ b/routes/breadcrumbs-bo.php
@@ -2,6 +2,7 @@
use App\Models\ActivityLog;
use App\Models\Range;
+use App\Models\SeasonalSection;
use App\Models\StaticPage;
use App\Models\User;
use Diglactic\Breadcrumbs\Breadcrumbs;
@@ -71,3 +72,23 @@ Breadcrumbs::for('bo.ranges.duplicate', function (Generator $trail) {
$trail->parent('bo.ranges.index');
$trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
});
+
+// * SEASONAL SECTIONS
+Breadcrumbs::for('bo.seasonalsections.index', function (Generator $trail) {
+ $trail->push(
+ Str::ucfirst(trans_choice('models.classes.seasonal_section', '*')),
+ route('bo.seasonalsections.index', ['sort_col' => 'updated_at', 'sort_way' => 'desc'])
+ );
+});
+Breadcrumbs::for('bo.seasonalsections.create', function (Generator $trail) {
+ $trail->parent('bo.seasonalsections.index');
+ $trail->push(Str::ucfirst(trans('crud.actions.create')), route('bo.seasonalsections.create'));
+});
+Breadcrumbs::for('bo.seasonalsections.edit', function (Generator $trail, SeasonalSection $seasonal_section) {
+ $trail->parent('bo.seasonalsections.index');
+ $trail->push(Str::ucfirst(trans('crud.actions.edit')), route('bo.seasonalsections.edit', $seasonal_section));
+});
+Breadcrumbs::for('bo.seasonalsections.duplicate', function (Generator $trail) {
+ $trail->parent('bo.seasonalsections.index');
+ $trail->push(Str::ucfirst(trans('crud.actions.duplicate')));
+});
diff --git a/routes/web-bo.php b/routes/web-bo.php
index 70aed87..11af57b 100644
--- a/routes/web-bo.php
+++ b/routes/web-bo.php
@@ -4,6 +4,7 @@ use App\Http\Controllers\Bo\ActivityLogsController;
use App\Http\Controllers\Bo\DashboardController;
use App\Http\Controllers\Bo\StaticPageController;
use App\Http\Controllers\Bo\RangeController;
+use App\Http\Controllers\Bo\SeasonalSectionController;
use App\Http\Controllers\Bo\UsersController;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
@@ -62,6 +63,18 @@ Route::prefix('bo')
RangeController::class, 'duplicate'
])->name('ranges.duplicate');
+ // * SEASONAL SECTIONS.
+ Route::resource('seasonalsections', SeasonalSectionController::class)->except('show')
+ ->parameters(['seasonalsections' => 'seasonal_section'])
+ ->withoutMiddleware('htmlsanitize')
+ ->middleware('htmlsanitize:text');
+ Route::patch('/seasonalsections/{seasonal_section}/change-published', [
+ SeasonalSectionController::class, 'changePublished'
+ ])->name('seasonalsections.change-published');
+ Route::get('/seasonalsections/{seasonal_section}/duplicate', [
+ SeasonalSectionController::class, 'duplicate'
+ ])->name('seasonalsections.duplicate');
+
Route::middleware('can:isConceptor')->group(function () {
// * ACTIVITY LOGS.
Route::resource('activity_logs', ActivityLogsController::class)->only(['index', 'show']);