1
|
|
|
<?php namespace Arcanesoft\Seo\Http\Controllers\Admin; |
2
|
|
|
|
3
|
|
|
use Arcanesoft\Seo\Entities\Locales; |
4
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Pages\CreatePageRequest; |
5
|
|
|
use Arcanesoft\Seo\Http\Requests\Admin\Pages\UpdatePageRequest; |
6
|
|
|
use Arcanesoft\Seo\Models\Page; |
7
|
|
|
use Arcanesoft\Seo\Policies; |
8
|
|
|
use Illuminate\Support\Facades\Log; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PagesController |
12
|
|
|
* |
13
|
|
|
* @package Arcanesoft\Seo\Http\Controllers\Admin |
14
|
|
|
* @author ARCANEDEV <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class PagesController extends Controller |
17
|
|
|
{ |
18
|
|
|
/* ----------------------------------------------------------------- |
19
|
|
|
| Constructor |
20
|
|
|
| ----------------------------------------------------------------- |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* PagesController constructor. |
25
|
|
|
*/ |
26
|
|
|
public function __construct() |
27
|
|
|
{ |
28
|
|
|
parent::__construct(); |
29
|
|
|
|
30
|
|
|
$this->setCurrentPage('seo-pages'); |
31
|
|
|
$this->addBreadcrumbRoute(trans('seo::pages.titles.pages'), 'admin::seo.pages.index'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/* ----------------------------------------------------------------- |
35
|
|
|
| Main Methods |
36
|
|
|
| ----------------------------------------------------------------- |
37
|
|
|
*/ |
38
|
|
|
|
39
|
|
|
public function index() |
40
|
|
|
{ |
41
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_LIST); |
42
|
|
|
|
43
|
|
|
$pages = Page::with(['footers'])->paginate(50); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$this->setTitle($title = trans('seo::pages.titles.pages-list')); |
46
|
|
|
$this->addBreadcrumb($title); |
47
|
|
|
|
48
|
|
|
return $this->view('admin.pages.index', compact('pages')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function create() |
52
|
|
|
{ |
53
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_CREATE); |
54
|
|
|
|
55
|
|
|
$locales = Locales::all(); |
56
|
|
|
|
57
|
|
|
$this->setTitle($title = trans('seo::pages.titles.new-page')); |
58
|
|
|
$this->addBreadcrumb($title); |
59
|
|
|
|
60
|
|
|
return $this->view('admin.pages.create', compact('locales')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function store(CreatePageRequest $request) |
64
|
|
|
{ |
65
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_CREATE); |
66
|
|
|
|
67
|
|
|
$page = Page::createOne( |
68
|
|
|
$request->getValidatedValidated() |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
$this->transNotification('created', ['name' => $page->name], $page->toArray()); |
72
|
|
|
|
73
|
|
|
return redirect()->route('admin::seo.pages.show', [$page]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function show(Page $page) |
77
|
|
|
{ |
78
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_SHOW); |
79
|
|
|
|
80
|
|
|
$page->load(['footers.seo']); |
81
|
|
|
|
82
|
|
|
$this->setTitle($title = trans('seo::pages.titles.page-details')); |
83
|
|
|
$this->addBreadcrumb($title); |
84
|
|
|
|
85
|
|
|
return $this->view('admin.pages.show', compact('page')); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function edit(Page $page) |
89
|
|
|
{ |
90
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_UPDATE); |
91
|
|
|
|
92
|
|
|
$locales = Locales::all(); |
93
|
|
|
|
94
|
|
|
$this->setTitle($title = trans('seo::pages.titles.edit-page')); |
95
|
|
|
$this->addBreadcrumb($title); |
96
|
|
|
|
97
|
|
|
return $this->view('admin.pages.edit', compact('page', 'locales')); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function update(Page $page, UpdatePageRequest $request) |
101
|
|
|
{ |
102
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_UPDATE); |
103
|
|
|
|
104
|
|
|
$page->updateOne( |
105
|
|
|
$request->getValidatedValidated() |
106
|
|
|
); |
107
|
|
|
|
108
|
|
|
$this->transNotification('updated', ['name' => $page->name], $page->toArray()); |
109
|
|
|
|
110
|
|
|
return redirect()->route('admin::seo.pages.show', [$page]); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function delete(Page $page) |
114
|
|
|
{ |
115
|
|
|
$this->authorize(Policies\PagesPolicy::PERMISSION_DELETE); |
116
|
|
|
|
117
|
|
|
$page->delete(); |
118
|
|
|
|
119
|
|
|
return $this->jsonResponseSuccess([ |
120
|
|
|
'message' => $this->transNotification('deleted', ['name' => $page->name], $page->toArray()) |
121
|
|
|
]); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/* ----------------------------------------------------------------- |
125
|
|
|
| Other Methods |
126
|
|
|
| ----------------------------------------------------------------- |
127
|
|
|
*/ |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Notify with translation. |
131
|
|
|
* |
132
|
|
|
* @todo: Refactor this method to the core package ? |
133
|
|
|
* |
134
|
|
|
* @param string $action |
135
|
|
|
* @param array $replace |
136
|
|
|
* @param array $context |
137
|
|
|
* |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
protected function transNotification($action, array $replace = [], array $context = []) |
141
|
|
|
{ |
142
|
|
|
$title = trans("seo::pages.messages.{$action}.title"); |
143
|
|
|
$message = trans("seo::pages.messages.{$action}.message", $replace); |
144
|
|
|
|
145
|
|
|
Log::info($message, $context); |
146
|
|
|
$this->notifySuccess($message, $title); |
147
|
|
|
|
148
|
|
|
return $message; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: