si-klinik/sk-klinik.my.id/app/Livewire/Guest/NewsShow.php

37 lines
892 B
PHP

<?php
namespace App\Livewire\Guest;
use App\Models\News;
use Livewire\Component;
use Illuminate\Support\Str;
class NewsShow extends Component
{
public News $news;
// Nama variabel di mount() harus sama dengan nama parameter di Route {news:slug}
public function mount(News $news)
{
// Pastikan berita sudah dipublikasikan
if (!$news->is_published) {
abort(404);
}
$this->news = $news;
// Tambah view count
$this->news->increment('view_count');
}
public function render()
{
return view('livewire.guest.news-show')
->layout('components.guest-layout', [
'title' => $this->news->title,
// SEO: Mengambil potongan konten untuk meta description
'description' => Str::limit(strip_tags($this->news->content), 160)
]);
}
}