From 59fcfc2779a43ad8e906716d2cc253a77ef82b63 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 19 Jun 2019 20:54:48 -0600 Subject: [PATCH] Update PageController --- app/Http/Controllers/PageController.php | 26 ++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 101f981b..58e8745b 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Auth; +use Auth, Cache; use App\Page; class PageController extends Controller @@ -13,6 +13,14 @@ class PageController extends Controller $this->middleware(['auth', 'admin']); } + protected function cacheKeys() { + return [ + '/site/about' => 'site:about', + '/site/privacy' => 'site:privacy', + '/site/terms' => 'site:terms', + ]; + } + protected function authCheck($admin_only = false) { $auth = $admin_only ? @@ -48,9 +56,25 @@ class PageController extends Controller $page->title = $request->input('title'); $page->active = (bool) $request->input('active'); $page->save(); + if($page->cached) { + $keys = $this->cacheKeys(); + $key = $keys[$page->slug]; + Cache::forget($key); + } return response()->json(['msg' => 200]); } + public function delete(Request $request) + { + $this->validate($request, [ + 'id' => 'required|integer|min:1|exists:pages,id' + ]); + + $page = Page::findOrFail($request->input('id')); + $page->delete(); + return redirect(route('admin.settings.pages')); + } + public function generatePage(Request $request) { $this->validate($request, [