From c9c6004694d226c70c443d7c8d73a9af2a16f988 Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Wed, 4 Oct 2023 21:15:51 +0800 Subject: [PATCH] Add (debugbar) Update (post detail): Show detailed post Update (post url): Improve url structure --- .../Controllers/Front/FrontPostController.php | 14 +- composer.json | 1 + composer.lock | 152 +++++++++++++++++- .../front/partials/post_detail.blade.php | 6 +- routes/web.php | 5 +- storage/debugbar/.gitignore | 2 + 6 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 storage/debugbar/.gitignore diff --git a/app/Http/Controllers/Front/FrontPostController.php b/app/Http/Controllers/Front/FrontPostController.php index bff9b70..6296881 100644 --- a/app/Http/Controllers/Front/FrontPostController.php +++ b/app/Http/Controllers/Front/FrontPostController.php @@ -14,7 +14,19 @@ class FrontPostController extends Controller { - public function index(Request $request, $slug) + public function redirect(Request $request, $slug) + { + $post = Post::where('slug', $slug)->where('status', 'publish')->first(); + + if (is_null($post)) { + return abort(404); + } + + return redirect()->route('front.post',['category_slug' => $post->category->slug, 'slug' => $post->slug]); + + } + + public function index(Request $request, $category_slug, $slug) { $post = Post::where('slug', $slug)->where('status', 'publish')->first(); diff --git a/composer.json b/composer.json index 178b577..c96a048 100644 --- a/composer.json +++ b/composer.json @@ -35,6 +35,7 @@ "watson/active": "^7.0" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.9", "fakerphp/faker": "^1.9.1", "laravel/pint": "^1.0", "laravel/sail": "^1.18", diff --git a/composer.lock b/composer.lock index e39df8f..0df159d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "188bab118ada68d970c9a2927e68c673", + "content-hash": "4bb8fad2567f5c7b3e6a1682fe4eaf39", "packages": [ { "name": "artesaos/seotools", @@ -8934,6 +8934,90 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.9.2", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "bfd0131c146973cab164e50f5cdd8a67cc60cab1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/bfd0131c146973cab164e50f5cdd8a67cc60cab1", + "reference": "bfd0131c146973cab164e50f5cdd8a67cc60cab1", + "shasum": "" + }, + "require": { + "illuminate/routing": "^9|^10", + "illuminate/session": "^9|^10", + "illuminate/support": "^9|^10", + "maximebf/debugbar": "^1.18.2", + "php": "^8.0", + "symfony/finder": "^6" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench-dusk": "^5|^6|^7|^8", + "phpunit/phpunit": "^8.5.30|^9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.8-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-debugbar/issues", + "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.9.2" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2023-08-25T18:43:57+00:00" + }, { "name": "brianium/paratest", "version": "v7.2.7", @@ -9814,6 +9898,72 @@ }, "time": "2023-09-11T17:37:09+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.19.0", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30f65f18f7ac086255a77a079f8e0dcdd35e828e", + "reference": "30f65f18f7ac086255a77a079f8e0dcdd35e828e", + "shasum": "" + }, + "require": { + "php": "^7.1|^8", + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^4|^5|^6" + }, + "require-dev": { + "phpunit/phpunit": ">=7.5.20 <10.0", + "twig/twig": "^1.38|^2.7|^3.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "support": { + "issues": "https://github.com/maximebf/php-debugbar/issues", + "source": "https://github.com/maximebf/php-debugbar/tree/v1.19.0" + }, + "time": "2023-09-19T19:53:10+00:00" + }, { "name": "mockery/mockery", "version": "1.6.6", diff --git a/resources/views/front/partials/post_detail.blade.php b/resources/views/front/partials/post_detail.blade.php index b2719cb..ea2eb4b 100644 --- a/resources/views/front/partials/post_detail.blade.php +++ b/resources/views/front/partials/post_detail.blade.php @@ -1,6 +1,10 @@
- {{ $post->category->name }} + @if(isset($category)) + Under {{ $category->name }} {{ $post->category->name }} + @else + Under {{ $post->category->name }} + @endif

{{ $post->title }}

@if (!is_empty($post->published_at))
{{ $post->published_at->format('M j') }}
diff --git a/routes/web.php b/routes/web.php index ac7209d..aecd97a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -25,7 +25,10 @@ Route::get('/news', [App\Http\Controllers\Front\FrontListController::class, 'index'])->name('front.all'); -Route::get('/news/{slug}', [App\Http\Controllers\Front\FrontPostController::class, 'index'])->name('front.post'); +Route::get('/news/{slug}', [App\Http\Controllers\Front\FrontPostController::class, 'redirect'])->name('front.post.redirect'); + +Route::get('/{category_slug}/{slug}', [App\Http\Controllers\Front\FrontPostController::class, 'index'])->name('front.post'); + Route::get('/{category_slug}', [App\Http\Controllers\Front\FrontListController::class, 'category']) ->where('category_slug', '^(automotive|business|trading|information-technology|marketing|office|telecommunications|food-drink|collectibles|pets|photography|hobbies-gifts|hunting-fishing|law|politics|home-garden|shopping|fashion-clothing|real-estate|family|wedding|immigration|society|education|languages|health|beauty|psychology|wellness|religion-spirituality|tips-tricks|how-to|holiday|world-festivals|travel|outdoors|computer|phones|gadgets|technology|social-networks|ai)$') diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore