From 5fe3fcac6128cd2d78f14ef01b5e421987a21d38 Mon Sep 17 00:00:00 2001 From: Rico van Zelst Date: Tue, 12 Dec 2023 12:32:42 +0100 Subject: [PATCH] feat: add working posts index This commit adds pagination functionality to the posts index page. The code changes include: - Sorting the posts by descending date - Paginating the posts with 6 items per page - Creating a new component called "Listposts" for rendering the paginated posts - Adding a new view file for the "Listposts" component - Updating the blade template of the posts index page to use the "Listposts" component and pass in the paginated posts The purpose of these changes is to improve user experience by displaying a limited number of posts per page and providing navigation links for easier browsing. --- app/Http/Controllers/PostsController.php | 10 ++- app/View/Components/Posts/Listposts.php | 21 ++++++ composer.json | 1 + composer.lock | 73 ++++++++++++++++++- content/posts/hello-world.md | 9 ++- .../components/posts/listposts.blade.php | 24 ++++++ resources/views/posts/index.blade.php | 12 +-- 7 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 app/View/Components/Posts/Listposts.php create mode 100644 resources/views/components/posts/listposts.blade.php diff --git a/app/Http/Controllers/PostsController.php b/app/Http/Controllers/PostsController.php index ccba1b7..75d7cfb 100644 --- a/app/Http/Controllers/PostsController.php +++ b/app/Http/Controllers/PostsController.php @@ -4,14 +4,18 @@ namespace App\Http\Controllers; use Spatie\Sheets\Facades\Sheets; use Spatie\Sheets\Sheet; +use CreativeCrafts\Paginate\Facades\Paginate; class PostsController extends Controller { public function index() { - $posts = Sheets::all(); - - return view('posts.index', compact('posts')); + $posts = Sheets::all()->sortByDesc('date'); + $paginatedPosts = Paginate::collection($posts, 6); + + return view('posts.index', [ + 'posts' => $paginatedPosts, + ]); } public function show(Sheet $post) diff --git a/app/View/Components/Posts/Listposts.php b/app/View/Components/Posts/Listposts.php new file mode 100644 index 0000000..2b13101 --- /dev/null +++ b/app/View/Components/Posts/Listposts.php @@ -0,0 +1,21 @@ + +
+ @foreach($posts as $post) +
+ + + + Post Thumbnail +
+

{{ $post->title }}

+

{{ $post->description }}

+
+ +
+ @endforeach +
+
+ {{ $posts->links() }} +
+ diff --git a/resources/views/posts/index.blade.php b/resources/views/posts/index.blade.php index 91f7bb2..10e1cb6 100644 --- a/resources/views/posts/index.blade.php +++ b/resources/views/posts/index.blade.php @@ -1,8 +1,7 @@ @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('description', 'Explore all our blog posts on Heimerdinger.LoL. Posts about League of Legends and more.') @section('content')
@@ -10,11 +9,8 @@ such as Dark Cosmic Jhin, HEARTSTEEL Ezreal, PROJECT: Vayne and more!') class="text-3xl font-bold text-center text-transparent uppercase sm:text-4xl bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text"> Posts -

Latest posts about League of Legends

- @foreach($posts as $post) - {{ $post->title }} - {{ $post->description}} - - @endforeach +

Our latest posts about League of + Legends

+
@endsection