aboutsummaryrefslogtreecommitdiff
path: root/app/Http/Controllers/GuestbookController.php
blob: 3fd179b2159b23204f054d9dfa7dc3a8b76ac697 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace App\Http\Controllers;

use App\Models\GuestbookEntry;
use Illuminate\Http\Request;
use Illuminate\Http\RedirectResponse;
use Illuminate\Contracts\View\View;
use Illuminate\Validation\ValidationException;
use UAParser\Parser;

class GuestbookController extends Controller {
    public function show(): View {
        $entries = GuestbookEntry::selectEntries();
        $parser = Parser::create();

        return view('guestbook')
            ->with('entries', $entries)
            ->with('parser', $parser);
    }

    /**
     * Creates a new guestbook entry
     *
     * @param Request $request
     * @return RedirectResponse
     * @throws ValidationException
     */
    public function addEntry(Request $request): RedirectResponse {
        GuestbookEntry::insertGuestbookEntry($request);
        return back()->with('success', 'Entry submitted successfully!');
    }
}