Update PageController

This commit is contained in:
Daniel Supernault 2019-06-19 20:54:48 -06:00
parent aca5114fcb
commit 59fcfc2779
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 25 additions and 1 deletions

View File

@ -3,7 +3,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Auth; use Auth, Cache;
use App\Page; use App\Page;
class PageController extends Controller class PageController extends Controller
@ -13,6 +13,14 @@ class PageController extends Controller
$this->middleware(['auth', 'admin']); $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) protected function authCheck($admin_only = false)
{ {
$auth = $admin_only ? $auth = $admin_only ?
@ -48,9 +56,25 @@ class PageController extends Controller
$page->title = $request->input('title'); $page->title = $request->input('title');
$page->active = (bool) $request->input('active'); $page->active = (bool) $request->input('active');
$page->save(); $page->save();
if($page->cached) {
$keys = $this->cacheKeys();
$key = $keys[$page->slug];
Cache::forget($key);
}
return response()->json(['msg' => 200]); 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) public function generatePage(Request $request)
{ {
$this->validate($request, [ $this->validate($request, [