diff --git a/app/Http/Controllers/Bo/GammesController.php b/app/Http/Controllers/Bo/GammesController.php new file mode 100644 index 0000000..fc77e5e --- /dev/null +++ b/app/Http/Controllers/Bo/GammesController.php @@ -0,0 +1,108 @@ +get(); + // $gammes = Gamme::whereNull('parent_id')->orderBy('created_at', 'DESC')->get(); + + return view('back.gammes.index', compact('gammes')); + } + + /** + * Show the form for creating a new resource. + * + * @param Gamme $gamme + * @return \Illuminate\Http\Response + */ + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass + public function create(Gamme $gamme) + { + return view('back.gammes.create', compact('gamme')); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\StoreGammeRequest $request + * @return \Illuminate\Http\Response + */ + public function store(StoreGammeRequest $request) + { + $gamme = new Gamme($request->validated()); + $response = $this->changeUniquePostOnTop($gamme->on_top); + + if ($response) { + $response = $gamme->saveOrFail(); + } + if (!$response) { + return redirect()->route('bo.gammes.edit', $gamme->id)->with('error', 'L\'actualité n\'a pas été créee'); + } + return redirect()->route('bo.gammes.edit', $gamme->id)->with('success', 'Actualité créée !'); + } + + /** + * Show the form for editing the specified resource. + * + * @param Gamme $gamme + * @return \Illuminate\Http\Response + */ + // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass + public function edit(Gamme $gamme) + { + return view('back.gammes.edit', compact('gamme')); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\UpdateGammeRequest $request + * @param Gamme $gamme + * @return \Illuminate\Http\Response + */ + public function update(Gamme $gamme, UpdateGammeRequest $request) + { + $gamme->fill($request->validated()); + + $response = $this->changeUniquePostOnTop($gamme->on_top); + + if ($response) { + $response = $gamme->saveOrFail(); + } + if (!$response) { + return redirect()->route('bo.gammes.edit', $gamme->id) + ->with('error', trans('La modification a échoué')); + } + + return redirect()->route('bo.gammes.edit', $gamme->id) + ->with('success', trans('Modifications enregistrées !')); + } + + /** + * Remove the specified resource from storage. + * + * @param Gamme $gamme + * @return \Illuminate\Http\Response + */ + public function destroy(Gamme $gamme) + { + if (!$gamme->delete()) { + return redirect()->route('bo.gammes.index')->with('error', trans('La suppression a échoué')); + } + + return redirect()->route('bo.gammes.index')->with('success', trans('Suppression faite avec succès')); + } +} diff --git a/app/Http/Requests/StoreGammeRequest.php b/app/Http/Requests/StoreGammeRequest.php new file mode 100644 index 0000000..baf834e --- /dev/null +++ b/app/Http/Requests/StoreGammeRequest.php @@ -0,0 +1,37 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + 'parent_gamme_id' => 'required|exists:gammes,id', + 'title' => 'required|max:255', + 'text' => 'required|max:255', + 'color' => 'sometimes', + 'picture' => 'required|image|mimes:jpeg,png,jpg|max:1024|dimensions:width=575,height=375', + 'alt_text_picture' => 'required|max:255', + 'banner' => 'required|image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1169,height=243', + 'alt_text_banner' => 'required|max:255', + ]; + } +} diff --git a/app/Http/Requests/UpdateGammeRequest.php b/app/Http/Requests/UpdateGammeRequest.php new file mode 100644 index 0000000..3907090 --- /dev/null +++ b/app/Http/Requests/UpdateGammeRequest.php @@ -0,0 +1,34 @@ + [ + 'sometimes', + 'image', + 'mimes:jpeg,png,jpg', + 'max:1024', + 'dimensions:width=575,height=375' + ], + 'banner' => [ + 'sometimes', + 'image', + 'mimes:jpeg,png,jpg', + 'max:2048', + 'dimensions:width=1169,height=243' + ], + ] + ); + } +} diff --git a/app/Models/Gamme.php b/app/Models/Gamme.php new file mode 100644 index 0000000..cde8708 --- /dev/null +++ b/app/Models/Gamme.php @@ -0,0 +1,55 @@ +picture) { + $gamme->picture = Utils::storeImage($gamme->picture, $gamme->getTable()); + } + if ($gamme->banner) { + $gamme->banner = Utils::storeImage($gamme->banner, $gamme->getTable()); + } + }); + + static::updating(function (Gamme $gamme) { + if ($gamme->picture) { + $gamme->picture = Utils::storeImage($gamme->picture, $gamme->getTable()); + } + if ($gamme->banner) { + $gamme->banner = Utils::storeImage($gamme->banner, $gamme->getTable()); + } + }); + parent::boot(); + } + + public function childGammes() + { + return $this->hasMany(Gamme::class, 'parent_gamme_id'); + } + + public function parentGamme() + { + return $this->belongsTo(Gamme::class); + } +} diff --git a/config/bo.php b/config/bo.php index 83b9bae..5eba6c3 100644 --- a/config/bo.php +++ b/config/bo.php @@ -27,4 +27,9 @@ return [ 'post_news_image_maxwidth' => '380', 'post_news_image_maxheight' => '298', + 'gamme_image_maxwidth' => '575', + 'gamme_image_maxheight' => '375', + 'gamme_banner_maxwidth' => '1169', + 'gamme_banner_maxheight' => '243', + ]; diff --git a/database/factories/GammeFactory.php b/database/factories/GammeFactory.php new file mode 100644 index 0000000..ce0c586 --- /dev/null +++ b/database/factories/GammeFactory.php @@ -0,0 +1,28 @@ + null, + 'title' => $this->faker->word(), + 'text' => $this->faker->text(5), + 'color' => $this->faker->hexColor(), + 'picture' => new SplFileInfo(resource_path('assets/images/cookrange.jpg')), + 'alt_text_picture' => $this->faker->sentence(10), + 'banner' => new SplFileInfo(resource_path('assets/images/cat_bckg.jpg')), + 'alt_text_banner' => $this->faker->sentence(10), + ]; + } +} diff --git a/database/migrations/2021_12_20_145730_create_gammes_table.php b/database/migrations/2021_12_20_145730_create_gammes_table.php new file mode 100644 index 0000000..0f7e35a --- /dev/null +++ b/database/migrations/2021_12_20_145730_create_gammes_table.php @@ -0,0 +1,39 @@ +id(); + $table->smallInteger('parent_gamme_id')->nullable(); + $table->string('title'); + $table->string('text'); + $table->string('color')->nullable(); + $table->string('picture')->nullable(); + $table->string('alt_text_picture')->nullable(); + $table->string('banner')->nullable(); + $table->string('alt_text_banner')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('gammes'); + } +} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 60fef67..e02fde8 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -24,6 +24,7 @@ class DatabaseSeeder extends Seeder TextsSeeder::class, AdviceSeeder::class, PostsSeeder::class, + GammesSeeder::class, ]); } } diff --git a/database/seeders/GammesSeeder.php b/database/seeders/GammesSeeder.php new file mode 100644 index 0000000..ea92428 --- /dev/null +++ b/database/seeders/GammesSeeder.php @@ -0,0 +1,41 @@ +create() + ->each(function (Gamme $gamme) use (&$tabGammes) { + array_push($tabGammes, $gamme->color); + }); + + foreach ($tabGammes as $key => $value) { + for ($i = 0; $i < 2; $i++) { + $gamme = new Gamme(); + $id = $key + 1; + $gamme->parent_gamme_id = $id; + $gamme->title = 'lorem ipsum'; + $gamme->text = 'lorem ipsum set doloris'; + $gamme->color = $value; + $gamme->picture = new SplFileInfo(resource_path('assets/images/cookrange.jpg')); + $gamme->alt_text_picture = 'lorem utus garis'; + $gamme->banner = new SplFileInfo(resource_path('assets/images/cat_bckg.jpg')); + $gamme->alt_text_banner = 'redus faros'; + $gamme->save(); + } + } + } +} diff --git a/public/assets/images/cookrange.jpg b/public/assets/images/cookrange.jpg index c552d3b..a8d412a 100644 Binary files a/public/assets/images/cookrange.jpg and b/public/assets/images/cookrange.jpg differ diff --git a/resources/assets/images/cookrange.jpg b/resources/assets/images/cookrange.jpg index c552d3b..a8d412a 100644 Binary files a/resources/assets/images/cookrange.jpg and b/resources/assets/images/cookrange.jpg differ diff --git a/resources/views/back/gammes/create.blade.php b/resources/views/back/gammes/create.blade.php new file mode 100644 index 0000000..5ab8e93 --- /dev/null +++ b/resources/views/back/gammes/create.blade.php @@ -0,0 +1,66 @@ +@extends('layouts.backend') + +@section('content') +
+ @csrf +
+

+ < {{ __('Slides') }} {{ __('Création') }}

+
+
+
+ + @include('back.slides.form-inputs') + +
+@endsection + +@section('scripts') + +@endsection \ No newline at end of file diff --git a/resources/views/back/gammes/edit.blade.php b/resources/views/back/gammes/edit.blade.php new file mode 100644 index 0000000..da8ee95 --- /dev/null +++ b/resources/views/back/gammes/edit.blade.php @@ -0,0 +1,67 @@ +@extends('layouts.backend') + +@section('content') +
+ @method('PUT') + @csrf +
+

+ < {{ __('Slide') }} {{ __('Edition') }}

+
+
+
+ + @include('back.slides.form-inputs') + +
+@endsection + +@section('scripts') + +@endsection \ No newline at end of file diff --git a/resources/views/back/gammes/form-inputs.blade.php b/resources/views/back/gammes/form-inputs.blade.php new file mode 100644 index 0000000..6b064df --- /dev/null +++ b/resources/views/back/gammes/form-inputs.blade.php @@ -0,0 +1,61 @@ +
+ + + @include('back.modules.input-error', ['inputName'=>'title']) +
+
+ + + @include('back.modules.input-error', ['inputName'=>'text']) +
+
+
+ + @if ($gamme->picture !== null) +
+
+ {{$gamme->title}} + @endif + @include('back.modules.input-error', ['inputName'=>'picture']) +
+
+ + + @include('back.modules.input-error', ['inputName'=>'alt_text_picture']) +
+
+
+ + @if ($gamme->banner !== null) +
+
+ {{$gamme->title}} + @endif + @include('back.modules.input-error', ['inputName'=>'banner']) +
+
+ + + @include('back.modules.input-error', ['inputName'=>'alt_text_banner']) +
+ +
+
+ + +
+
+
+
+ @include('back.modules.input-error', ['inputName'=>'gamme_parent_id']) +
+
+ + + @include('back.modules.input-error', ['inputName'=>'colorInput']) +
diff --git a/resources/views/back/gammes/index.blade.php b/resources/views/back/gammes/index.blade.php new file mode 100644 index 0000000..951058e --- /dev/null +++ b/resources/views/back/gammes/index.blade.php @@ -0,0 +1,49 @@ +@extends('layouts.backend') + +@section('content') +
+

{{ __('Gammes') }} {{ __('Liste') }}

+ + @if ($errors->any()) + @foreach($errors->all() as $error) + {{ $error }} + @endforeach + @endif + {{ __('Créer une gamme') }} +
+ + + + + + + + + + + + + @foreach($gammes as $gamme) + + + + + + + + + @endforeach + +
{{ __('Nom') }}{{ __('Texte') }}{{ __('Vignette') }}{{ __('Couleur') }}{{ __('Gamme parente') }}
{{$gamme->title}}{{$gamme->text}} + @if (isset($gamme->parentGamme)) + {{$gamme->parentGamme->title}} + @endif + + {{ __('Éditer') }} +
+ @method('DELETE') + @csrf + +
+
+@endsection \ No newline at end of file diff --git a/resources/views/layouts/backend/sidenav.blade.php b/resources/views/layouts/backend/sidenav.blade.php index 3bcf9f6..fea5168 100644 --- a/resources/views/layouts/backend/sidenav.blade.php +++ b/resources/views/layouts/backend/sidenav.blade.php @@ -58,6 +58,22 @@ + {{-- PAGE PRODUITS --}} +
+

+ +

+
+ +
+
{{-- PAGE ACTUALITES --}}

diff --git a/resources/views/layouts/frontend/app-header.blade.php b/resources/views/layouts/frontend/app-header.blade.php index d6ef8f5..210b527 100644 --- a/resources/views/layouts/frontend/app-header.blade.php +++ b/resources/views/layouts/frontend/app-header.blade.php @@ -31,7 +31,7 @@ - + diff --git a/routes/web.php b/routes/web.php index b7aec23..f8f25f0 100644 --- a/routes/web.php +++ b/routes/web.php @@ -13,6 +13,7 @@ use App\Http\Controllers\Bo\AdviceController; use App\Http\Controllers\Bo\EncartsController; +use App\Http\Controllers\Bo\GammesController; use App\Http\Controllers\Bo\HomeController; use App\Http\Controllers\Bo\PictoBrandsController; use App\Http\Controllers\Bo\PictosController; @@ -77,6 +78,7 @@ Route::prefix('bo') Route::resource('pictos', PictosController::class)->except(['show']); Route::resource('posts', PostsController::class)->except(['show']); Route::resource('pictobrands', PictoBrandsController::class)->except(['show']); + Route::resource('gammes', GammesController::class)->except(['show']); Route::resource('advice', AdviceController::class) ->except(['index', 'create', 'store', 'destroy', 'show']); Route::resource('texts', TextsController::class)->except(['show']);