From 25c3675c2b450300a9f9e4683b05dfbfe2025dea Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Tue, 12 Dec 2023 10:23:15 +0100 Subject: [PATCH] feat: Add PostsController and configure routes - Added a new file `PostsController.php` in the `app/Http/Controllers` directory. - Implemented the `index()` method to retrieve all posts using the Sheets facade. - Implemented the `show()` method to display a single post using route model binding with Sheets. - Updated the `RouteServiceProvider.php` file to bind the 'post' route parameter to retrieve posts from the Sheets collection. - Created a new configuration file `sheets.php` in the `config` directory, defining default settings for collections and their corresponding sheet classes, path parsers, content parsers, and extensions. - Added a new markdown file `hello-world.md` in the `content/posts` directory as an example post. - Created two new blade view files: `index.blade.php` and `show.blade.php`, under the `resources/views/posts` directory, for displaying lists of posts and individual post details respectively. - Modified the existing web routes (`web.php`) to include routes for accessing posts. The changes enable users to view all posts on `/posts`, as well as access individual post details at `/post/{post}`. --- app/Http/Controllers/PostsController.php | 22 ++++++++++++++++++++++ app/Providers/RouteServiceProvider.php | 9 +++++++++ config/filesystems.php | 5 +++++ config/sheets.php | 14 ++++++++++++++ content/posts/hello-world.md | 9 +++++++++ resources/views/posts/index.blade.php | 20 ++++++++++++++++++++ resources/views/posts/show.blade.php | 0 routes/web.php | 12 ++++++++++++ 8 files changed, 91 insertions(+) create mode 100644 app/Http/Controllers/PostsController.php create mode 100644 config/sheets.php create mode 100644 content/posts/hello-world.md create mode 100644 resources/views/posts/index.blade.php create mode 100644 resources/views/posts/show.blade.php diff --git a/app/Http/Controllers/PostsController.php b/app/Http/Controllers/PostsController.php new file mode 100644 index 0000000..ccba1b7 --- /dev/null +++ b/app/Http/Controllers/PostsController.php @@ -0,0 +1,22 @@ +by($request->user()?->id ?: $request->ip()); }); @@ -36,5 +39,11 @@ class RouteServiceProvider extends ServiceProvider Route::middleware('web') ->group(base_path('routes/web.php')); }); + + Route::bind('post', function ($path) { + return $this->app->make(Sheets::class) + ->collection('posts') + ->get($path) ?? abort(404); + }); } } diff --git a/config/filesystems.php b/config/filesystems.php index 4afc1fc..71576c4 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -56,6 +56,11 @@ return [ 'throw' => false, ], + 'posts' => [ + 'driver' => 'local', + 'root' => base_path('content/posts'), + ] + ], /* diff --git a/config/sheets.php b/config/sheets.php new file mode 100644 index 0000000..451412c --- /dev/null +++ b/config/sheets.php @@ -0,0 +1,14 @@ + 'posts', + + 'collections' => [ + 'posts' => [ + 'sheet_class' => Spatie\Sheets\Sheet::class, + 'path_parser' => Spatie\Sheets\PathParsers\SlugParser::class, + 'content_parser' => Spatie\Sheets\ContentParsers\MarkdownWithFrontMatterParser::class, + 'extension' => 'md', + ] + ], +]; diff --git a/content/posts/hello-world.md b/content/posts/hello-world.md new file mode 100644 index 0000000..d565e8a --- /dev/null +++ b/content/posts/hello-world.md @@ -0,0 +1,9 @@ +--- +title: Hello, world! +description: Welcome to Sheets! +date: 2020-07-01 +--- + +# Hello, world! + +Welcome to Sheets! diff --git a/resources/views/posts/index.blade.php b/resources/views/posts/index.blade.php new file mode 100644 index 0000000..91f7bb2 --- /dev/null +++ b/resources/views/posts/index.blade.php @@ -0,0 +1,20 @@ +@extends('layouts.app') + +@section('title', 'Heimerdinger.LoL • Posts') +@section('description', 'Explore all champion skins on Heimerdinger.LoL. Find detailed information on popular skins +such as Dark Cosmic Jhin, HEARTSTEEL Ezreal, PROJECT: Vayne and more!') + +@section('content') +
+

+ Posts

+

Latest posts about League of Legends

+ @foreach($posts as $post) + {{ $post->title }} + {{ $post->description}} + + @endforeach +
+@endsection diff --git a/resources/views/posts/show.blade.php b/resources/views/posts/show.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/routes/web.php b/routes/web.php index 82db5af..94f5e62 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use App\Http\Controllers\AboutController; use App\Http\Controllers\AssetsController; use App\Http\Controllers\ChampionController; use App\Http\Controllers\FAQController; +use App\Http\Controllers\PostsController; use App\Http\Controllers\SaleController; use App\Http\Controllers\SummonerEmoteController; use Illuminate\Support\Facades\Route; @@ -76,6 +77,17 @@ Route::get('/about/faq/heimerdinger', [ 'heimerdinger' ])->name('about.faq.heimerdinger'); +// Posts +Route::get('/posts', [ + PostsController::class, + 'index' +])->name('posts.index'); + +Route::get('/post/{post}', [ + PostsController::class, + 'show' +])->name('posts.show'); + // Pulse Route::get(config('app.login_route'), function () { return redirect('/pulse');