<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Page; use Illuminate\Http\Request; use Illuminate\Support\Str; class PagesController extends Controller {public function index(){return view('admin.pages',['items'=>Page::latest()->get()]);} public function store(Request $r){$d=$r->validate(['title'=>'required','content'=>'required','is_active'=>'nullable']);$d['slug']=Str::slug($d['title']);$d['is_active']=$r->boolean('is_active');Page::updateOrCreate(['slug'=>$d['slug']],$d);return back()->with('ok','Page saved.');} public function destroy(Page $page){$page->delete();return back();} public function toggle(Page $page){$page->update(['is_active'=>!$page->is_active]);return back();}}