46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Post;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
|
|
class PeraturanController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$posts = Post::with(['kategori', 'subkategori'])
|
|
->whereHas('kategori', function($query) {
|
|
$query->where('NamaKategori', 'Peraturan');
|
|
})
|
|
->where('IsPublish', true)
|
|
->orderBy('created_at', 'desc')
|
|
->get();
|
|
|
|
return Inertia::render('Peraturan', [
|
|
'posts' => $posts
|
|
]);
|
|
}
|
|
|
|
public function show($slug)
|
|
{
|
|
$article = Post::with(['kategori', 'subkategori'])
|
|
->where('SlugPost', $slug)
|
|
->firstOrFail();
|
|
|
|
$relatedArticles = Post::with(['kategori', 'subkategori'])
|
|
->where('KategoriId', $article->KategoriId)
|
|
->where('PostId', '!=', $article->PostId)
|
|
->where('IsPublish', true)
|
|
->latest()
|
|
->take(5)
|
|
->get();
|
|
|
|
return Inertia::render('detail/PeraturanDetail', [
|
|
'article' => $article,
|
|
'relatedArticles' => $relatedArticles
|
|
]);
|
|
}
|
|
}
|