From 7c16dc53b55aa50d6c9ac0bdea2f51fbbf2b20b0 Mon Sep 17 00:00:00 2001 From: Frankie B Date: Sun, 16 Jul 2023 21:02:51 +0100 Subject: feat: site admin (#8) --- routes/web.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'routes/web.php') diff --git a/routes/web.php b/routes/web.php index 6185449..7284bc3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -40,4 +40,46 @@ Route::post('/guestbook', 'App\Http\Controllers\GuestbookController@guestbookpos ->name('guestbookPost') ->middleware('rate_limit'); +Route::get('/admin', function () { + if (!auth()->check()) { + return view('errors.no-auth'); + } + return view('pages.admin.index'); +}); + +Route::get('/admin/guestbook', function () { + if (!auth()->check()) { + return view('errors.no-auth'); + } + return view('pages.admin.guestbook'); +}); + +Route::get('/admin/guestbook/delete', function () { + if (!auth()->check()) { + return view('errors.no-auth'); + } + + $id = request()->input('id'); + $entry = DB::table('guestbook_entries')->find($id); + + if ($entry) { + // Render a confirmation view + return View::make('pages.admin.guestbook-del-confirm', compact('entry')); + } else { + return view('errors.generic-error') + ->with('error', "Entry not found") + ->with('description', "The specified entry does not exist!"); + } +}); + +Route::post('/admin/guestbook/delete', function () { + if (!auth()->check()) { + return view('errors.no-auth'); + } + + $id = request()->input('id'); + DB::table('guestbook_entries')->where('id', $id)->delete(); + + return back()->with('success', 'Entry deleted successfully!'); +}); -- cgit v1.2.3-54-g00ecf