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.
This commit is contained in:
Rico van Zelst
2023-12-12 12:32:42 +01:00
parent 25c3675c2b
commit 5fe3fcac61
7 changed files with 134 additions and 16 deletions

View File

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