1
|
|
|
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin; |
2
|
|
|
|
3
|
|
|
use Arcanedev\LaravelSeo\Entities\RedirectStatuses; |
4
|
|
|
use Arcanedev\LaravelSeo\Models\Redirect; |
5
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Redirects\CreateRedirectRequest; |
6
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Redirects\UpdateRedirectRequest; |
7
|
|
|
use Illuminate\Http\Request; |
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
|
|
|
* @todo: Add authorization checks |
17
|
|
|
*/ |
18
|
|
|
class RedirectsController extends Controller |
19
|
|
|
{ |
20
|
|
|
/* ----------------------------------------------------------------- |
21
|
|
|
| Constructor |
22
|
|
|
| ----------------------------------------------------------------- |
23
|
|
|
*/ |
24
|
|
|
/** |
25
|
|
|
* MetasController constructor. |
26
|
|
|
*/ |
27
|
|
|
public function __construct() |
28
|
|
|
{ |
29
|
|
|
parent::__construct(); |
30
|
|
|
|
31
|
|
|
$this->setCurrentPage('seo-redirects'); |
32
|
|
|
$this->addBreadcrumbRoute('Redirections', 'admin::seo.redirects.index'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/* ----------------------------------------------------------------- |
36
|
|
|
| Main Methods |
37
|
|
|
| ----------------------------------------------------------------- |
38
|
|
|
*/ |
39
|
|
|
public function index() |
40
|
|
|
{ |
41
|
|
|
$this->setTitle($title = 'List of Redirections'); |
42
|
|
|
$this->addBreadcrumb($title); |
43
|
|
|
|
44
|
|
|
$redirects = Redirect::all(); |
45
|
|
|
|
46
|
|
|
return $this->view('admin.redirects.index', compact('redirects')); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function create() |
50
|
|
|
{ |
51
|
|
|
$this->setTitle($title = 'New Redirection'); |
52
|
|
|
$this->addBreadcrumb($title); |
53
|
|
|
|
54
|
|
|
$statuses = RedirectStatuses::all(); |
55
|
|
|
|
56
|
|
|
return $this->view('admin.redirects.create', compact('statuses')); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function store(CreateRedirectRequest $request) |
60
|
|
|
{ |
61
|
|
|
$redirect = Redirect::createOne( |
62
|
|
|
$request->get('old_url'), |
63
|
|
|
$request->get('new_url'), |
64
|
|
|
$request->get('status') |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
$message = "The redirection was created successfully !"; |
68
|
|
|
Log::info($message, $redirect->toArray()); |
69
|
|
|
$this->notifySuccess($message, 'Redirection created !'); |
70
|
|
|
|
71
|
|
|
return redirect()->route('admin::seo.redirects.index'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function show(Redirect $redirect) |
75
|
|
|
{ |
76
|
|
|
$this->setTitle($title = 'Redirection details'); |
77
|
|
|
$this->addBreadcrumb($title); |
78
|
|
|
|
79
|
|
|
return $this->view('admin.redirects.show', compact('redirect')); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function edit(Redirect $redirect) |
83
|
|
|
{ |
84
|
|
|
$this->setTitle($title = 'Edit Redirection'); |
85
|
|
|
$this->addBreadcrumb($title); |
86
|
|
|
|
87
|
|
|
$statuses = RedirectStatuses::all(); |
88
|
|
|
|
89
|
|
|
return $this->view('admin.redirects.edit', compact('redirect', 'statuses')); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function update(Redirect $redirect, UpdateRedirectRequest $request) |
93
|
|
|
{ |
94
|
|
|
$redirect->update( |
95
|
|
|
$request->only(['old_url', 'new_url', 'status']) |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$message = "The redirection was updated successfully !"; |
99
|
|
|
Log::info($message, $redirect->toArray()); |
100
|
|
|
$this->notifySuccess($message, 'Redirection updated !'); |
101
|
|
|
|
102
|
|
|
return redirect()->route('admin::seo.redirects.show', [$redirect]); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function delete(Redirect $redirect) |
106
|
|
|
{ |
107
|
|
|
$redirect->delete(); |
108
|
|
|
|
109
|
|
|
$message = "The redirection was deleted successfully !"; |
110
|
|
|
Log::info($message, $redirect->toArray()); |
111
|
|
|
$this->notifySuccess($message, 'Redirection deleted !'); |
112
|
|
|
|
113
|
|
|
return json_response()->success($message); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|