|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 05/03/2016 |
|
6
|
|
|
* Time: 20:30. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Plugins\Pages; |
|
10
|
|
|
|
|
11
|
|
|
use App\Model\Menu; |
|
12
|
|
|
use App\Model\Page; |
|
13
|
|
|
use Illuminate\Http\Request; |
|
14
|
|
|
use App\Plugins\PluginEngine; |
|
15
|
|
|
use Illuminate\Support\Facades\DB; |
|
16
|
|
|
use App\Classes\Repositories\PageRepository; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Controller. |
|
20
|
|
|
*/ |
|
21
|
|
|
class BackendController extends PluginEngine |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var PageRepository |
|
25
|
|
|
*/ |
|
26
|
|
|
private $repository; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* AdminController constructor. |
|
30
|
|
|
* @param PageRepository $repository |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(PageRepository $repository) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->repository = $repository; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Display a listing of the resource. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function index() |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->make('index')->with('pages', $this->repository->all()); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Show the form for creating a new resource. |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response |
|
49
|
|
|
*/ |
|
50
|
|
|
public function create() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->make('create'); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Store a newly created resource in storage. |
|
57
|
|
|
* |
|
58
|
|
|
* @param \Illuminate\Http\Request $request |
|
59
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
60
|
|
|
*/ |
|
61
|
|
|
public function store(Request $request) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->validate($request, ['title' => 'required|unique:pages,seo_title,NULL,id,deleted_at,NULL|min:3|max:255']); |
|
64
|
|
|
|
|
65
|
|
|
$this->save($request, new Page); |
|
66
|
|
|
|
|
67
|
|
|
return redirect()->route('admin.pages.index'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Display the specified resource. |
|
72
|
|
|
* |
|
73
|
|
|
* @param string $name |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
|
|
public function show(string $name) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
return false; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Show the form for editing the specified resource. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $name |
|
85
|
|
|
* @return \Illuminate\Contracts\View\View|\Illuminate\Http\Response |
|
86
|
|
|
*/ |
|
87
|
|
|
public function edit(string $name) |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->make('edit')->with('page', $this->repository->whereName($name)); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Update the specified resource in storage. |
|
94
|
|
|
* |
|
95
|
|
|
* @param \Illuminate\Http\Request $request |
|
96
|
|
|
* @param string $name |
|
97
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
98
|
|
|
*/ |
|
99
|
|
|
public function update(Request $request, string $name) |
|
100
|
|
|
{ |
|
101
|
|
|
$page = $this->repository->whereName($name); |
|
102
|
|
|
|
|
103
|
|
|
$this->validate($request, ['title'=>'required|min:3|max:255|unique:pages,seo_title,'.$page->id.',id,deleted_at,NULL']); |
|
|
|
|
|
|
104
|
|
|
|
|
105
|
|
|
$this->save($request, $page); |
|
|
|
|
|
|
106
|
|
|
|
|
107
|
|
|
return redirect()->route('admin.pages.index'); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Remove the specified resource from storage. |
|
112
|
|
|
* |
|
113
|
|
|
* @param $slug |
|
114
|
|
|
* @param PageRepository $repository |
|
115
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
116
|
|
|
* @throws \Exception |
|
117
|
|
|
*/ |
|
118
|
|
|
public function destroy($slug, PageRepository $repository) |
|
119
|
|
|
{ |
|
120
|
|
|
$page = $repository->whereName($slug); |
|
121
|
|
|
|
|
122
|
|
|
if ($page->editable) { |
|
123
|
|
|
$repository->whereName($slug)->delete(); |
|
|
|
|
|
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return redirect()->route('admin.pages.index'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Resource data for saving. |
|
131
|
|
|
* |
|
132
|
|
|
* @param Request $request |
|
133
|
|
|
* @param Page $page |
|
134
|
|
|
*/ |
|
135
|
|
|
private function save(Request $request, Page $page) |
|
136
|
|
|
{ |
|
137
|
|
|
$page->seo_title = $request['title']; |
|
138
|
|
|
$page->creator_id = $request['creator'] ?: account()->id; |
|
139
|
|
|
$page->seo_keywords = $request['keywords']; |
|
140
|
|
|
$page->seo_description = $request['description']; |
|
141
|
|
|
$page->content = $request['content']; |
|
142
|
|
|
$page->sitemap = true; //$request['sitemap'] ? true : false; |
|
|
|
|
|
|
143
|
|
|
$page->enabled = true; //$request['enabled'] ? true : false; |
|
|
|
|
|
|
144
|
|
|
|
|
145
|
|
|
// we should not allow important slugs to be changed. |
|
146
|
|
|
if ($page->editable == true) { |
|
147
|
|
|
$page->slug = str_slug($page->seo_title); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
$page->save(); |
|
151
|
|
|
} |
|
152
|
|
|
} |
|
153
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.