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