refactor: improve filtering of hidden posts in PostsController

- Refactored the code in `PostsController.php` to filter out hidden posts before sorting by date for better performance and accuracy.
- Updated the blade template `listposts.blade.php` to adjust formatting and structure for displaying posts.
This commit is contained in:
Rico van Zelst
2024-04-01 16:27:07 +02:00
parent 7ad53814d3
commit 55a72607e2
2 changed files with 12 additions and 9 deletions

View File

@@ -10,7 +10,9 @@ class PostsController extends Controller
{
public function index()
{
$posts = Sheets::all()->sortByDesc('date');
$posts = Sheets::all()->filter(function ($post) {
return !$post->hidden;
})->sortByDesc('date');
$paginatedPosts = Paginate::collection($posts, 6);
return view('posts.index', [

View File

@@ -6,12 +6,13 @@
@if ($post->hidden)
@continue
@endif
<article class="relative items-center inline-block text-gray-200 border shadow-md bg-stone-800/40 rounded-2xl border-stone-800 hover:border-orange-500/10 hover:shadow-orange-500/10 h-80">
<span
class="absolute px-1 py-1 text-sm font-medium text-gray-100 rounded-lg top-4 left-4 bg-black/60">
<article
class="relative items-center inline-block text-gray-200 border shadow-md bg-stone-800/40 rounded-2xl border-stone-800 hover:border-orange-500/10 hover:shadow-orange-500/10 h-80">
<span class="absolute px-1 py-1 text-sm font-medium text-gray-100 rounded-lg top-4 left-4 bg-black/60">
<abbr itemprop="datePublished">{{ Carbon::parse($post->date)->format('F d, Y') }}</abbr>
</span>
<img src="{{ $post->thumbnail }}" alt="Post Thumbnail" class="object-cover w-full h-48 aspect-video rounded-t-2xl">
<img src="{{ $post->thumbnail }}" alt="Post Thumbnail"
class="object-cover w-full h-48 aspect-video rounded-t-2xl">
<div class="p-4">
<h2 class="mb-2 text-xl font-bold line-clamp-1" itemprop="name">{{ $post->title }}</h2>
<p class="text-sm line-clamp-3" itemprop="headline">{{ $post->description }}</p>