Skip to content

Commit

Permalink
Update PageController
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Jun 20, 2019
1 parent aca5114 commit 59fcfc2
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
use Auth, Cache;
use App\Page;

class PageController extends Controller
Expand All @@ -13,6 +13,14 @@ public function __construct()
$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 ?
Expand Down Expand Up @@ -48,9 +56,25 @@ public function store(Request $request)
$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, [
Expand Down

0 comments on commit 59fcfc2

Please sign in to comment.