<?php

namespace App\Http\Controllers;

use App\Models\Post;
use Illuminate\Http\Request;
use Inertia\Inertia;

class SekilasInfoController extends Controller
{
    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/SekilasInfoDetail', [
            'article' => $article,
            'relatedArticles' => $relatedArticles
        ]);
    }
}
