@php function kategoriWarna($nama) { $colors = [ 'bg-red-500', 'bg-green-500', 'bg-blue-500', 'bg-yellow-500', 'bg-purple-500', 'bg-pink-500', 'bg-indigo-500', 'bg-emerald-600', 'bg-cyan-600', 'bg-orange-500', 'bg-amber-600', 'bg-teal-500', ]; $index = crc32(strtolower($nama)) % count($colors); return $colors[$index]; } @endphp @extends('layouts.app') @section('title', 'Daftar Berita') {{-- Pastikan judul halaman sesuai --}} @section('head') {{-- Font Awesome untuk ikon --}} @endsection @section('content')
{{-- Pesan Flash (Sukses/Error) --}} @if(session('success')) @endif @if(session('error')) @endif

📰 Daftar Berita

Pencarian & Filter

{{-- mt-auto for alignment --}}
@forelse ($news as $item)
{{-- Badge Pinned --}} @if ($item->is_pinned) Disematkan @endif {{-- Media (Image/Video) --}} @php $ext = pathinfo($item->image ?? '', PATHINFO_EXTENSION); // Handle if image is null $isVideo = in_array(strtolower($ext), ['mp4', 'webm', 'ogg']); $hasMedia = $item->image && file_exists(public_path('storage/' . $item->image)); @endphp
{{-- Reduced height for more cards per row --}} @if ($hasMedia) @if ($isVideo) @else {{ $item->title }} @endif @else
Tidak ada media
@endif
{{-- Konten Berita --}}
{{-- Adjust height based on image height --}}

{{ $item->title }}

{{ $item->category }} {{ \Carbon\Carbon::parse($item->publish_date)->translatedFormat('d M Y') }}

{{ \Illuminate\Support\Str::limit(strip_tags($item->content), 100, '...') }}

{{-- View Count & Like Count --}}
{{ number_format($item->view_count) }} views {{ number_format($item->like_count) }} likes
Detail @auth @if (auth()->id() === $item->user_id) Edit
@csrf @method('DELETE')
@endif @endauth
@empty

Maaf, belum ada berita yang tersedia.

Coba sesuaikan filter atau pencarian Anda.

@endforelse
{{ $news->links('vendor.pagination.tailwind') }}
@endsection