<?php

namespace App\Http\Controllers;

use App\Models\Document;

class DocumentController extends Controller
{
    public function __construct()
    {
        $this->middleware('front');
    }

    /**
     * 문서 보기
     * @method GET
     * @see /document/{code}
     */
    public function index(string $code, Document $documentModel)
    {
        $document = $documentModel->findByCode($code);

        if (!$document->exists) {
            abort(404);
        }

        return view(layout('document'), [
            'title' => $document->subject,
            'content' => $document->content,
            'writeURL' => route('admin.page.document.edit', $document->id)
        ]);
    }
}
