|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Chadanuk\MiniCms\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Chadanuk\MiniCms\Page; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use Illuminate\Support\Facades\View; |
|
8
|
|
|
|
|
9
|
|
|
class PagesController |
|
10
|
|
|
{ |
|
11
|
|
|
public function show(Page $page, Request $request) |
|
12
|
|
|
{ |
|
13
|
|
|
if ($request->is('/')) { |
|
14
|
|
|
$page = Page::where('slug', 'home')->first(); |
|
15
|
|
|
} |
|
16
|
|
|
$viewPath = $page->getViewPath(); |
|
17
|
|
|
|
|
18
|
|
|
return View::make($viewPath, ['page' => $page]); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function index() |
|
22
|
|
|
{ |
|
23
|
|
|
$pages = Page::all(); |
|
24
|
|
|
if (View::exists('mini-cms.admin.pages.list')) { |
|
25
|
|
|
return View('mini-cms.admin.pages.list', ['pages' => $pages]); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
return View::make('mini-cms::admin.pages.list', ['pages' => $pages]); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function edit(Request $request, $id) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$page = Page::find($id); |
|
34
|
|
|
|
|
35
|
|
|
$page->fetchBlocks(); |
|
36
|
|
|
|
|
37
|
|
|
if (View::exists('mini-cms.admin.pages.edit')) { |
|
38
|
|
|
return View('mini-cms.admin.pages.edit', ['page' => $page]); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return View::make('mini-cms::admin.pages.edit', ['page' => $page]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function update(Request $request, $id) |
|
45
|
|
|
{ |
|
46
|
|
|
$page = Page::find($id); |
|
47
|
|
|
|
|
48
|
|
|
$page->update([ |
|
49
|
|
|
'name' => $request->get('name', $page->name), |
|
50
|
|
|
'slug' => $request->get('slug', $page->slug), |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
$page->updateBlocks($request->get('blocks')); |
|
54
|
|
|
|
|
55
|
|
|
return redirect()->route('mini-cms.pages.edit', ['id' => $id])->with('success', true); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function create() |
|
59
|
|
|
{ |
|
60
|
|
|
if (View::exists('mini-cms.admin.pages.create')) { |
|
61
|
|
|
return View('mini-cms.admin.pages.create'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return View::make('mini-cms::admin.pages.create'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function store(Request $request) |
|
68
|
|
|
{ |
|
69
|
|
|
$page = \MiniCms::createPage([ |
|
70
|
|
|
'name' => $request->get('name'), |
|
71
|
|
|
|
|
72
|
|
|
]); |
|
73
|
|
|
|
|
74
|
|
|
return redirect()->route('mini-cms.pages.edit', ['id' => $page->id])->with('success', true); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.