From 9ebecd7a8fd5f7aae5829f30391233ca3ba4c9f1 Mon Sep 17 00:00:00 2001 From: Charles T Date: Wed, 26 Jul 2023 11:15:28 +0800 Subject: [PATCH] Add (country category) --- app/Http/Controllers/Front/HomeController.php | 21 +++++-- app/View/Composers/CategoryComposer.php | 13 ++++- ...12_add_description_to_categories_table.php | 28 ++++++++++ .../views/front/country_category.blade.php | 56 +++++++++++++++++++ 4 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2023_07_26_021612_add_description_to_categories_table.php create mode 100644 resources/views/front/country_category.blade.php diff --git a/app/Http/Controllers/Front/HomeController.php b/app/Http/Controllers/Front/HomeController.php index 762b859..2e353db 100644 --- a/app/Http/Controllers/Front/HomeController.php +++ b/app/Http/Controllers/Front/HomeController.php @@ -23,12 +23,11 @@ public function country(Request $request, $country) { $country_locale = CountryLocale::where('slug', $country)->first(); - if (! is_null($country)) { - $categories = Category::where('country_locale_id', $country_locale->id)->get(); - + if (! is_null($country_locale)) { + $request->session()->put('view_country_locale', $country_locale); - return view('front.country', ['categories' => $categories, 'country_locale' => $country_locale]); + return view('front.country', ['country_locale' => $country_locale]); } return redirect()->route('home.country', ['country' => config('platform.general.fallback_country_slug')]); @@ -36,7 +35,19 @@ public function country(Request $request, $country) public function countryCategory(Request $request, $country, $category) { - return "{$country} : {$category}"; + $country_locale = CountryLocale::where('slug', $country)->first(); + + if (is_null($country_locale)) { + abort(404); + } + + $category = Category::where('slug', $category)->where('enabled', true)->first(); + + if (is_null($category)) + { + abort(404); + } + return view('front.country_category', ['country_locale' => $country_locale, 'category' => $category]); } public function posts(Request $request, $country) diff --git a/app/View/Composers/CategoryComposer.php b/app/View/Composers/CategoryComposer.php index f609013..9e9e5a5 100644 --- a/app/View/Composers/CategoryComposer.php +++ b/app/View/Composers/CategoryComposer.php @@ -2,6 +2,7 @@ namespace App\View\Composers; +use App\Models\CountryLocale; use App\Models\Category; use Illuminate\View\View; @@ -10,6 +11,16 @@ class CategoryComposer { public function compose(View $view) { - + $current_country_locale = request()->session()->get('view_country_locale'); + + if (is_null($current_country_locale)) + { + $current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug')); + } + + $categories = Category::where('country_locale_id', $current_country_locale->id)->get(); + + $view->with('categories', $categories); + } } diff --git a/database/migrations/2023_07_26_021612_add_description_to_categories_table.php b/database/migrations/2023_07_26_021612_add_description_to_categories_table.php new file mode 100644 index 0000000..5f1cbd7 --- /dev/null +++ b/database/migrations/2023_07_26_021612_add_description_to_categories_table.php @@ -0,0 +1,28 @@ +mediumText('description')->after('slug')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('categories', function (Blueprint $table) { + $table->dropColumn('description'); + }); + } +}; diff --git a/resources/views/front/country_category.blade.php b/resources/views/front/country_category.blade.php new file mode 100644 index 0000000..d8ed1cd --- /dev/null +++ b/resources/views/front/country_category.blade.php @@ -0,0 +1,56 @@ +@extends('layouts.front.app') + +@section('content') +
+ +
+

{{ $category->name }}

+

+ {{ $category->description }} +

+
+ +
+
+
+
+ + @for($i = 0; $i < 10; $i++) +
+ + +
+ +
+
+ Here is why a kitten catches mice faster than an adult cat.
+

+ This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer. +

+ +

+ #technology #gadgets + Updated 3 mins ago +

+ +
+ + ... + + +
+ + +
+ @endfor +
+
+ b +
+
+
+ +
+ +
+@endsection \ No newline at end of file