diff --git a/app/Http/Controllers/Bo/MomentsController.php b/app/Http/Controllers/Bo/MomentsController.php new file mode 100644 index 00000000..cd03f08e --- /dev/null +++ b/app/Http/Controllers/Bo/MomentsController.php @@ -0,0 +1,235 @@ + "Couleur 1", + "color-2" => 'Couleur 2', + "color-3" => 'Couleur 3', + "color-4" => "Couleur 4", + "color-5" => "Couleur 5", + "color-6" => "Couleur 6", + "color-7" => "Couleur 7", + "color-8" => "Couleur 8", + ]; + + private $featuredTypes = [ + "recettes" => "Recettes", + "produits" => "Produits", + "articles" => "Articles", + ]; + + public function index() + { + $m = Moments::all(); + return view('bo.moments.index', compact('m')); + } + + public function create() + { + $r = Recipes::all(); + return view('bo.moments.create', compact('r')) + ->with('colors', $this->colors) + ->with('featuredTypes', $this->featuredTypes) + ; + } + + public function store(Request $request) + { + $title = $request->title; + $description = $request->description; + $color = $request->color; + $picture = $request->picture; + $picture_bg = $request->picture_bg; + $picture_bg_r = $request->picture_bg_r; + $parallax = $request->parallax === null ? 0 : 1; + $starMoment = $request->star_moment === null ? 0 : 1; + $status = 0; + $featuredTitle = $request->featured_title; + $featuredText = $request->featured_text; + $featuredType = $request->featured_type; + $featuredIds = $request->featured_ids; + $featuredStatus = $request->featured_status === null ? 0 : 1; + $voucherPicture = $request->voucher_picture; + $voucherStatus = $request->voucher_status === null ? 0 : 1; + + $request->validate([ + 'title' => 'required|max:150', + 'description' => 'required|max:400', + 'color' => 'required|max:7', + 'picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=750,height=400', + 'picture_bg' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1200,height=750', + 'picture_bg_r' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=300', + 'featured_title' => 'required|max:150', + 'featured_text' => 'required|max:4000', + 'voucher_picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=580,height=330', + ]); + + $featuredIdsString = ''; + foreach ($featuredIds as $featuredId) { + $featuredIdsString .= $featuredId . ';'; + } + + $imageName = Str::slug($title) . '-le-gaulois.'.$picture->extension(); + $picture->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName); + $imageName_bg = Str::slug($title) . '-bg-le-gaulois.' . $picture_bg->extension(); + $picture_bg->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName_bg); + $imageName_bg_r = Str::slug($title) . '-bg-r-le-gaulois.' . $picture_bg_r->extension(); + $picture_bg_r->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName_bg_r); + $imageNameVoucher = Str::slug($title) . '-bon-reduction-le-gaulois.' . $voucherPicture->extension(); + $voucherPicture->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageNameVoucher); + + $m = new Moments(); + $m->title = $title; + $m->description = $description; + $m->color = $color; + $m->picture = date('Y') . '/' . date('m') . '/' . $imageName; + $m->picture_bg = date('Y') . '/' . date('m') . '/' . $imageName_bg; + $m->picture_bg_r = date('Y') . '/' . date('m') . '/' . $imageName_bg_r; + $m->parallax = $parallax; + $m->star_moment = $starMoment; + $m->status = $status; + $m->featured_title = $featuredTitle; + $m->featured_text = $featuredText; + $m->featured_type = $featuredType; + $m->featured_ids = $featuredIdsString; + $m->featured_status = $featuredStatus; + $m->voucher_picture = date('Y') . '/' . date('m') . '/' . $imageNameVoucher; + $m->voucher_status = $voucherStatus; + $m->save(); + + return redirect()->route('bo.moments.index'); + } + + public function edit($id) + { + $m = Moments::findOrFail($id); + $r = Recipes::all(); + return view('bo.moments.edit', compact('m', 'r')) + ->with('colors', $this->colors) + ->with('featuredTypes', $this->featuredTypes) + ; + } + + public function update(Request $request, $id) + { + $title = $request->title; + $description = $request->description; + $color = $request->color; + $picture = $request->picture; + $picture_bg = $request->picture_bg; + $picture_bg_r = $request->picture_bg_r; + $parallax = $request->parallax === null ? 0 : 1; + $starMoment = $request->star_moment === null ? 0 : 1; + $status = $request->status === null ? 0 : 1; + $featuredTitle = $request->featured_title; + $featuredText = $request->featured_text; + $featuredType = $request->featured_type; + $featuredIds = $request->featured_ids; + $featuredStatus = $request->featured_status === null ? 0 : 1; + $voucherPicture = $request->voucher_picture; + $voucherStatus = $request->voucher_status === null ? 0 : 1; + + $request->validate([ + 'title' => 'required|max:150', + 'description' => 'required|max:400', + 'color' => 'required|max:7', + 'featured_title' => 'required|max:150', + 'featured_text' => 'required|max:4000', + ]); + + + if ($picture !== null) { + $request->validate([ + 'picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=750,height=400', + ]); + } + if ($picture_bg !== null) { + $request->validate([ + 'picture_bg' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=1200,height=750', + ]); + } + if ($picture_bg_r !== null) { + $request->validate([ + 'picture_bg_r' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=500,height=300', + ]); + } + if ($voucherPicture !== null) { + $request->validate([ + 'voucher_picture' => 'image|mimes:jpeg,png,jpg|max:2048|dimensions:width=580,height=330', + ]); + } + + $featuredIdsString = ''; + foreach ($featuredIds as $featuredId) { + $featuredIdsString .= $featuredId . ';'; + } + + $m = Moments::findOrFail($id); + + if ($picture !== null) { + if (file_exists(public_path('images/moments/') . $m->picture)) + unlink(public_path('images/moments/') . $m->picture); + $imageName = Str::slug($title) . '-le-gaulois.'.$picture->extension(); + $picture->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName); + } + + if ($picture_bg !== null) { + if (file_exists(public_path('images/moments/') . $m->picture_bg)) + unlink(public_path('images/moments/') . $m->picture_bg); + $imageName_bg = Str::slug($title) . '-bg-le-gaulois.' . $picture_bg->extension(); + $picture_bg->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName_bg); + } + + if ($picture_bg_r !== null) { + if (file_exists(public_path('images/moments/') . $m->picture_bg_r)) + unlink(public_path('images/moments/') . $m->picture_bg_r); + $imageName_bg_r = Str::slug($title) . '-bg-r-le-gaulois.' . $picture_bg_r->extension(); + $picture_bg_r->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageName_bg_r); + } + + if ($voucherPicture !== null) { + if (file_exists(public_path('images/moments/') . $m->voucher_picture)) + unlink(public_path('images/moments/') . $m->voucher_picture); + $imageNameVoucher = Str::slug($title) . '-bon-reduction-le-gaulois.' . $voucherPicture->extension(); + $voucherPicture->move(public_path('images/moments/' . date('Y') . '/' . date('m') . '/'), $imageNameVoucher); + } + + $m->title = $title; + $m->description = $description; + $m->color = $color; + if ($picture !== null) + $m->picture = date('Y') . '/' . date('m') . '/' . $imageName; + if ($picture_bg !== null) + $m->picture_bg = date('Y') . '/' . date('m') . '/' . $imageName_bg; + if ($picture_bg_r !== null) + $m->picture_bg_r = date('Y') . '/' . date('m') . '/' . $imageName_bg_r; + $m->parallax = $parallax; + $m->star_moment = $starMoment; + $m->status = $status; + $m->featured_title = $featuredTitle; + $m->featured_text = $featuredText; + $m->featured_type = $featuredType; + $m->featured_ids = $featuredIdsString; + $m->featured_status = $featuredStatus; + if ($voucherPicture !== null) + $m->voucher_picture = date('Y') . '/' . date('m') . '/' . $imageNameVoucher; + $m->voucher_status = $voucherStatus; + $m->save(); + + return redirect()->route('bo.moments.edit', $m->id)->with('success', 'Enregistré !'); + } + + public function destroy($id) + { + // + } +} diff --git a/app/Models/Moments.php b/app/Models/Moments.php new file mode 100644 index 00000000..88a5c3ca --- /dev/null +++ b/app/Models/Moments.php @@ -0,0 +1,10 @@ + + .color-padding { + padding-left: 8px; + padding-right: 8px; + padding-top: 0px; + padding-bottom: 0px; + margin-right: 5px; + margin-left: 5px; + border: 1px solid #EFEBE9; + border-radius: 4px; + } + + .color-selected { + border: 1px solid #64DD17; + border-radius: 4px; + } + +@endsection + +@section('content') + +
+
+ Ajout d'un moment + Retour +
+
+ @csrf + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + +
+
+@endsection + +@section('scripts') + +@endsection diff --git a/resources/views/bo/moments/edit.blade.php b/resources/views/bo/moments/edit.blade.php new file mode 100644 index 00000000..63af60bc --- /dev/null +++ b/resources/views/bo/moments/edit.blade.php @@ -0,0 +1,289 @@ +@extends('layouts.bo') + +@section('styles') + +@endsection + +@section('content') +
+
+ Modification d'un moment + Retour +
+ @method('DELETE') + @csrf + +
+
+ +
+ @method('PUT') + @csrf + @if (session('success')) +
+ {{ session('success') }} +
+ @endif + @if ($errors->any()) +
+
    + @foreach ($errors->all() as $error) +
  • {{ $error }}
  • + @endforeach +
+
+ @endif + +
+
+@endsection + +@section('scripts') + +@endsection diff --git a/resources/views/bo/moments/index.blade.php b/resources/views/bo/moments/index.blade.php new file mode 100644 index 00000000..53fc33ad --- /dev/null +++ b/resources/views/bo/moments/index.blade.php @@ -0,0 +1,37 @@ +@extends('layouts.bo') + +@section('content') +
+
+ Liste des moments + Ajouter +
+ +
+ + + + + + + + + + @foreach($m as $moment) + + + + + + @endforeach + +
TitrePublié ?
{{$moment->title}} + @if ($moment->status === 1) + Oui + @else + Non + @endif + Éditer
+
+
+@endsection diff --git a/resources/views/layouts/bo.blade.php b/resources/views/layouts/bo.blade.php index b6024f54..33819a5f 100644 --- a/resources/views/layouts/bo.blade.php +++ b/resources/views/layouts/bo.blade.php @@ -20,6 +20,7 @@ + @yield('styles')
@@ -152,7 +153,13 @@ Ajouter
- En ce moment + Les réductions