<?php

namespace App\Http\Controllers\Panel;

use App\Http\Controllers\Controller;
use App\Models\Announcement;
use App\Models\AnnouncementRead;
use Illuminate\Support\Facades\Auth;

class AnnouncementController extends Controller
{
    public function index()
    {
        $announcements = Announcement::latest()->paginate(12);
        return view('panel.announcements.index', compact('announcements'));
    }

    public function show(Announcement $announcement)
    {
        AnnouncementRead::firstOrCreate([
            'user_id'         => Auth::id(),
            'announcement_id' => $announcement->id,
        ]);

        return view('panel.announcements.show', compact('announcement'));
    }
}
