<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\DiaryEntry;

class EntryController extends Controller
{
    public function saveDiaryEntry(Request $request)
    {
        $validatedData = $request->validate([
            'title' => 'required|string|max:80',
            'content' => 'required|string',
        ]);

        $entry = new DiaryEntry();
        $entry->title = $validatedData['title'];
        $entry->content = $validatedData['content'];
        $entry->user_id = auth()->id(); // Ensure the user is authenticated and set the user_id
        $entry->save();

        return redirect()->route('entry_creation_page')->with('success', 'Diary entry saved successfully.');
    }
}