|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebDevEtc\BlogEtc\Controllers\Admin; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
6
|
|
|
use Illuminate\Http\RedirectResponse; |
|
7
|
|
|
use Illuminate\Routing\Redirector; |
|
8
|
|
|
use Illuminate\View\View; |
|
9
|
|
|
use WebDevEtc\BlogEtc\Helpers; |
|
10
|
|
|
use WebDevEtc\BlogEtc\Middleware\UserCanManageBlogPosts; |
|
11
|
|
|
use WebDevEtc\BlogEtc\Requests\CategoryRequest; |
|
12
|
|
|
use WebDevEtc\BlogEtc\Services\CategoriesService; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class ManageCategoriesController. |
|
16
|
|
|
*/ |
|
17
|
|
|
class ManageCategoriesController extends Controller |
|
18
|
|
|
{ |
|
19
|
|
|
/** @var CategoriesService */ |
|
20
|
|
|
private $service; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* BlogEtcCategoryAdminController constructor. |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct(CategoriesService $service) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->middleware(UserCanManageBlogPosts::class); |
|
28
|
|
|
$this->service = $service; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Show list of categories. |
|
33
|
|
|
* |
|
34
|
|
|
* @return mixed |
|
35
|
|
|
*/ |
|
36
|
|
|
public function index(): View |
|
37
|
|
|
{ |
|
38
|
|
|
$categories = $this->service->indexPaginated(); |
|
39
|
|
|
|
|
40
|
|
|
return view( |
|
41
|
|
|
'blogetc_admin::categories.index', |
|
42
|
|
|
[ |
|
43
|
|
|
'categories' => $categories, |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @deprecated - use store() |
|
50
|
|
|
*/ |
|
51
|
|
|
public function store_category(CategoryRequest $request) |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->store($request); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Store a new category. |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store(CategoryRequest $request) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->service->create($request->validated()); |
|
62
|
|
|
|
|
63
|
|
|
Helpers::flashMessage('Saved new category'); |
|
64
|
|
|
|
|
65
|
|
|
return redirect(route('blogetc.admin.categories.index')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @deprecated - use edit() |
|
70
|
|
|
*/ |
|
71
|
|
|
public function edit_category($categoryId) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->edit($categoryId); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Show the edit form for category. |
|
78
|
|
|
*/ |
|
79
|
|
|
public function edit(int $categoryID): View |
|
80
|
|
|
{ |
|
81
|
|
|
$category = $this->service->find($categoryID); |
|
82
|
|
|
|
|
83
|
|
|
return view( |
|
84
|
|
|
'blogetc_admin::categories.edit_category', |
|
85
|
|
|
[ |
|
86
|
|
|
'category' => $category, |
|
87
|
|
|
] |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @deprecated - use create() |
|
93
|
|
|
*/ |
|
94
|
|
|
public function create_category() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->create(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Show the form for creating new category. |
|
101
|
|
|
*/ |
|
102
|
|
|
public function create(): View |
|
103
|
|
|
{ |
|
104
|
|
|
return view('blogetc_admin::categories.add_category'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @deprecated - use update() |
|
109
|
|
|
*/ |
|
110
|
|
|
public function update_category(CategoryRequest $request, $categoryId) |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->update($request, $categoryId); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Save submitted changes. |
|
117
|
|
|
* |
|
118
|
|
|
* @return RedirectResponse|Redirector |
|
119
|
|
|
*/ |
|
120
|
|
|
public function update(CategoryRequest $request, $categoryID) |
|
121
|
|
|
{ |
|
122
|
|
|
$category = $this->service->update($categoryID, $request->validated()); |
|
123
|
|
|
|
|
124
|
|
|
Helpers::flashMessage('Updated category'); |
|
125
|
|
|
|
|
126
|
|
|
return redirect($category->editUrl()); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @deprecated - use destroy() |
|
131
|
|
|
*/ |
|
132
|
|
|
public function destroy_category(CategoryRequest $request, $categoryId) |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->destroy($request, $categoryId); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Delete the category. |
|
139
|
|
|
*/ |
|
140
|
|
|
public function destroy(/** @scrutinizer ignore-unused */ CategoryRequest $request, $categoryID) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->service->delete($categoryID); |
|
143
|
|
|
|
|
144
|
|
|
return view('blogetc_admin::categories.deleted_category'); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|