1
|
|
|
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelApiHelper\Traits\JsonResponses; |
4
|
|
|
use Arcanedev\LaravelSeo\Entities\RedirectStatuses; |
5
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Redirects\CreateRedirectRequest; |
6
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Redirects\UpdateRedirectRequest; |
7
|
|
|
use Arcanesoft\Seo\Models\Redirect; |
8
|
|
|
use Arcanesoft\Seo\Policies\RedirectsPolicy; |
9
|
|
|
use Illuminate\Support\Facades\Log; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class RedirectsController |
13
|
|
|
* |
14
|
|
|
* @package Arcanesoft\Seo\Http\Controllers\Admin |
15
|
|
|
* @author ARCANEDEV <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class RedirectsController extends Controller |
18
|
|
|
{ |
19
|
|
|
/* ----------------------------------------------------------------- |
20
|
|
|
| Traits |
21
|
|
|
| ----------------------------------------------------------------- |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
use JsonResponses; |
25
|
|
|
|
26
|
|
|
/* ----------------------------------------------------------------- |
27
|
|
|
| Constructor |
28
|
|
|
| ----------------------------------------------------------------- |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* RedirectsController constructor. |
33
|
|
|
*/ |
34
|
|
|
public function __construct() |
35
|
|
|
{ |
36
|
|
|
parent::__construct(); |
37
|
|
|
|
38
|
|
|
$this->setCurrentPage('seo-redirects'); |
39
|
|
|
$this->addBreadcrumbRoute(trans('seo::redirects.titles.redirections'), 'admin::seo.redirects.index'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/* ----------------------------------------------------------------- |
43
|
|
|
| Main Methods |
44
|
|
|
| ----------------------------------------------------------------- |
45
|
|
|
*/ |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the index page. |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\View\View |
51
|
|
|
*/ |
52
|
|
|
public function index() |
53
|
|
|
{ |
54
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_LIST); |
55
|
|
|
|
56
|
|
|
$redirects = Redirect::paginate(50); |
57
|
|
|
|
58
|
|
|
$this->setTitle($title = trans('seo::redirects.titles.redirections-list')); |
59
|
|
|
$this->addBreadcrumb($title); |
60
|
|
|
|
61
|
|
|
return $this->view('admin.redirects.index', compact('redirects')); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the create form. |
66
|
|
|
* |
67
|
|
|
* @return \Illuminate\View\View |
68
|
|
|
*/ |
69
|
|
|
public function create() |
70
|
|
|
{ |
71
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_CREATE); |
72
|
|
|
|
73
|
|
|
$statuses = RedirectStatuses::all(); |
74
|
|
|
|
75
|
|
|
$this->setTitle($title = trans('seo::redirects.titles.create-redirection')); |
76
|
|
|
$this->addBreadcrumb($title); |
77
|
|
|
|
78
|
|
|
return $this->view('admin.redirects.create', compact('statuses')); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Store the new redirect. |
83
|
|
|
* |
84
|
|
|
* @param \Arcanesoft\Seo\Http\Requests\Admin\Redirects\CreateRedirectRequest $request |
85
|
|
|
* |
86
|
|
|
* @return \Illuminate\Http\RedirectResponse |
87
|
|
|
*/ |
88
|
|
|
public function store(CreateRedirectRequest $request) |
89
|
|
|
{ |
90
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_CREATE); |
91
|
|
|
|
92
|
|
|
$redirect = Redirect::createOne( |
93
|
|
|
$request->getValidatedInputs() |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
$this->transNotification('created', [], $redirect->toArray()); |
97
|
|
|
|
98
|
|
|
return redirect()->route('admin::seo.redirects.show', [$redirect]); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Show the redirect details page. |
103
|
|
|
* |
104
|
|
|
* @param \Arcanesoft\Seo\Models\Redirect $redirect |
105
|
|
|
* |
106
|
|
|
* @return \Illuminate\View\View |
107
|
|
|
*/ |
108
|
|
|
public function show(Redirect $redirect) |
109
|
|
|
{ |
110
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_SHOW); |
111
|
|
|
|
112
|
|
|
$this->setTitle($title = trans('seo::redirects.titles.redirection-details')); |
113
|
|
|
$this->addBreadcrumb($title); |
114
|
|
|
|
115
|
|
|
return $this->view('admin.redirects.show', compact('redirect')); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get the edit page. |
120
|
|
|
* |
121
|
|
|
* @param \Arcanesoft\Seo\Models\Redirect $redirect |
122
|
|
|
* |
123
|
|
|
* @return \Illuminate\View\View |
124
|
|
|
*/ |
125
|
|
|
public function edit(Redirect $redirect) |
126
|
|
|
{ |
127
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_UPDATE); |
128
|
|
|
|
129
|
|
|
$statuses = RedirectStatuses::all(); |
130
|
|
|
|
131
|
|
|
$this->setTitle($title = trans('seo::redirects.titles.edit-redirection')); |
132
|
|
|
$this->addBreadcrumb($title); |
133
|
|
|
|
134
|
|
|
return $this->view('admin.redirects.edit', compact('redirect', 'statuses')); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Update the redirect. |
139
|
|
|
* |
140
|
|
|
* @param \Arcanesoft\Seo\Models\Redirect $redirect |
141
|
|
|
* @param \Arcanesoft\Seo\Http\Requests\Admin\Redirects\UpdateRedirectRequest $request |
142
|
|
|
* |
143
|
|
|
* @return \Illuminate\Http\RedirectResponse |
144
|
|
|
*/ |
145
|
|
|
public function update(Redirect $redirect, UpdateRedirectRequest $request) |
146
|
|
|
{ |
147
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_UPDATE); |
148
|
|
|
|
149
|
|
|
$redirect->update($request->getValidatedInputs()); |
150
|
|
|
|
151
|
|
|
$this->transNotification('updated', [], $redirect->toArray()); |
152
|
|
|
|
153
|
|
|
return redirect()->route('admin::seo.redirects.show', [$redirect]); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Delete a redirect record. |
158
|
|
|
* |
159
|
|
|
* @param \Arcanesoft\Seo\Models\Redirect $redirect |
160
|
|
|
* |
161
|
|
|
* @return \Illuminate\Http\JsonResponse |
162
|
|
|
*/ |
163
|
|
|
public function delete(Redirect $redirect) |
164
|
|
|
{ |
165
|
|
|
$this->authorize(RedirectsPolicy::PERMISSION_DELETE); |
166
|
|
|
|
167
|
|
|
$redirect->delete(); |
168
|
|
|
|
169
|
|
|
return $this->jsonResponseSuccess([ |
170
|
|
|
'message' => $this->transNotification('deleted', [], $redirect->toArray()) |
171
|
|
|
]); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/* ----------------------------------------------------------------- |
175
|
|
|
| Other Methods |
176
|
|
|
| ----------------------------------------------------------------- |
177
|
|
|
*/ |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Notify with translation. |
181
|
|
|
* |
182
|
|
|
* @param string $action |
183
|
|
|
* @param array $replace |
184
|
|
|
* @param array $context |
185
|
|
|
* |
186
|
|
|
* @return string |
187
|
|
|
*/ |
188
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
189
|
|
|
{ |
190
|
|
|
$title = trans("seo::redirects.messages.{$action}.title"); |
191
|
|
|
$message = trans("seo::redirects.messages.{$action}.message", $replace); |
192
|
|
|
|
193
|
|
|
Log::info($message, $context); |
194
|
|
|
$this->notifySuccess($message, $title); |
195
|
|
|
|
196
|
|
|
return $message; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|