Add (country category)

This commit is contained in:
2023-07-26 11:15:28 +08:00
parent 2c42553599
commit 9ebecd7a8f
4 changed files with 112 additions and 6 deletions

View File

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

View File

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

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->mediumText('description')->after('slug')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('categories', function (Blueprint $table) {
$table->dropColumn('description');
});
}
};

View File

@@ -0,0 +1,56 @@
@extends('layouts.front.app')
@section('content')
<div class="container py-3">
<div class="mb-5">
<h1 class="h2 fw-bold">{{ $category->name }}</h1>
<p class="text-secondary">
{{ $category->description }}
</p>
</div>
<div class="row justify-content-center">
<div class="col-12 col-lg-11 col-xl-9 col-xxl-8">
<div class="row">
<div class="col-md-8 col-lg-8 col-xl-8 bg-primary">
@for($i = 0; $i < 10; $i++)
<div class="my-3">
<div class="card mb-3">
<div class="card-body">
<h5 class="card-title">
<a class="text-decoration-none" href="{{ route('home.country.post', ['country' => $country_locale->country_iso, 'post' => str_random() ]) }}">Here is why a kitten catches mice faster than an adult cat.</a></h5>
<p class="card-text">
This is a wider card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
</p>
<p class="card-text">
<small><a class="text-decoration-none" href="{{ route('home.country.category', ['country' => $country_locale->country_iso, 'category' => 'technology' ]) }}">#technology</a> <a class="text-decoration-none" href="{{ route('home.country.category', ['country' => $country_locale->country_iso, 'category' => 'gadgets' ]) }}">#gadgets</a></small>
<small class="text-body-secondary">Updated 3 mins ago</small>
</p>
</div>
<a class="card-img-top" href="{{ route('home.country.post', ['country' => $country_locale->country_iso, 'post' => str_random() ]) }}">
<img src="https://placekitten.com/400/300" class="card-img-top" alt="...">
</a>
</div>
</div>
@endfor
</div>
<div class="col-md-4 col-lg-4 col-xl-4 bg-secondary">
b
</div>
</div>
</div>
</div>
</div>
@endsection