1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SleepingOwl\Admin\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Routing\Controller; |
7
|
|
|
use SleepingOwl\Admin\Form\FormElements; |
8
|
|
|
use SleepingOwl\Admin\Form\Columns\Column; |
9
|
|
|
use SleepingOwl\Admin\Display\DisplayTable; |
10
|
|
|
use Illuminate\Contracts\Support\Renderable; |
11
|
|
|
use SleepingOwl\Admin\Display\DisplayTabbed; |
12
|
|
|
use Illuminate\Validation\ValidationException; |
13
|
|
|
use SleepingOwl\Admin\Contracts\AdminInterface; |
14
|
|
|
use SleepingOwl\Admin\Model\ModelConfiguration; |
15
|
|
|
use Illuminate\Contracts\Foundation\Application; |
16
|
|
|
use SleepingOwl\Admin\Contracts\Form\FormInterface; |
17
|
|
|
use SleepingOwl\Admin\Contracts\ModelConfigurationInterface; |
18
|
|
|
use SleepingOwl\Admin\Contracts\Display\ColumnEditableInterface; |
19
|
|
|
|
20
|
|
|
class AdminController extends Controller |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var \DaveJamesMiller\Breadcrumbs\Manager |
24
|
|
|
*/ |
25
|
|
|
protected $breadcrumbs; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var AdminInterface |
29
|
|
|
*/ |
30
|
|
|
protected $admin; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var |
34
|
|
|
*/ |
35
|
|
|
private $parentBreadcrumb = 'home'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Application |
39
|
|
|
*/ |
40
|
|
|
public $app; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* AdminController constructor. |
44
|
|
|
* |
45
|
|
|
* @param Request $request |
46
|
|
|
* @param AdminInterface $admin |
47
|
|
|
* @param Application $application |
48
|
|
|
*/ |
49
|
|
|
public function __construct(Request $request, AdminInterface $admin, Application $application) |
50
|
|
|
{ |
51
|
|
|
$this->app = $application; |
52
|
|
|
$this->admin = $admin; |
53
|
|
|
$this->breadcrumbs = $admin->template()->breadcrumbs(); |
54
|
|
|
|
55
|
|
|
$admin->navigation()->setCurrentUrl($request->getUri()); |
56
|
|
|
|
57
|
|
|
if (! $this->breadcrumbs->exists('home')) { |
58
|
|
|
$this->breadcrumbs->register('home', function ($breadcrumbs) { |
59
|
|
|
$breadcrumbs->push(trans('sleeping_owl::lang.dashboard'), route('admin.dashboard')); |
60
|
|
|
}); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$breadcrumbs = []; |
64
|
|
|
|
65
|
|
|
if ($currentPage = $admin->navigation()->getCurrentPage()) { |
66
|
|
|
foreach ($currentPage->getPathArray() as $page) { |
67
|
|
|
$breadcrumbs[] = [ |
68
|
|
|
'id' => $page['id'], |
69
|
|
|
'title' => $page['title'], |
70
|
|
|
'url' => $page['url'], |
71
|
|
|
'parent' => $this->parentBreadcrumb, |
72
|
|
|
]; |
73
|
|
|
|
74
|
|
|
$this->parentBreadcrumb = $page['id']; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
foreach ($breadcrumbs as $breadcrumb) { |
79
|
|
|
if (! $this->breadcrumbs->exists($breadcrumb['id'])) { |
80
|
|
|
$this->breadcrumbs->register($breadcrumb['id'], function ($breadcrumbs) use ($breadcrumb) { |
81
|
|
|
$breadcrumbs->parent($breadcrumb['parent']); |
82
|
|
|
$breadcrumbs->push($breadcrumb['title'], $breadcrumb['url']); |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
public function getParentBreadcrumb() |
92
|
|
|
{ |
93
|
|
|
return $this->parentBreadcrumb; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $parentBreadcrumb |
98
|
|
|
*/ |
99
|
|
|
public function setParentBreadcrumb($parentBreadcrumb) |
100
|
|
|
{ |
101
|
|
|
$this->parentBreadcrumb = $parentBreadcrumb; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
106
|
|
|
*/ |
107
|
|
|
public function getDashboard() |
108
|
|
|
{ |
109
|
|
|
return $this->renderContent( |
110
|
|
|
$this->admin->template()->view('dashboard'), |
|
|
|
|
111
|
|
|
trans('sleeping_owl::lang.dashboard') |
|
|
|
|
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param ModelConfigurationInterface $model |
117
|
|
|
* |
118
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
119
|
|
|
* |
120
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
121
|
|
|
*/ |
122
|
|
|
public function getDisplay(ModelConfigurationInterface $model) |
123
|
|
|
{ |
124
|
|
|
if (! $model->isDisplayable()) { |
125
|
|
|
abort(404); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $this->render($model, $model->fireDisplay()); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param ModelConfigurationInterface $model |
133
|
|
|
* |
134
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
135
|
|
|
* |
136
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
137
|
|
|
*/ |
138
|
|
|
public function getCreate(ModelConfigurationInterface $model) |
139
|
|
|
{ |
140
|
|
|
if (! $model->isCreatable()) { |
141
|
|
|
abort(404); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$create = $model->fireCreate(); |
145
|
|
|
|
146
|
|
|
$this->registerBreadcrumb($model->getCreateTitle(), $this->parentBreadcrumb); |
|
|
|
|
147
|
|
|
|
148
|
|
|
return $this->render($model, $create, $model->getCreateTitle()); |
|
|
|
|
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param ModelConfigurationInterface $model |
153
|
|
|
* @param Request $request |
154
|
|
|
* |
155
|
|
|
* @return \Illuminate\Http\RedirectResponse |
156
|
|
|
*/ |
157
|
|
|
public function postStore(ModelConfigurationInterface $model, Request $request) |
158
|
|
|
{ |
159
|
|
|
if (! $model->isCreatable()) { |
160
|
|
|
abort(404); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$createForm = $model->fireCreate(); |
164
|
|
|
$nextAction = $request->input('next_action'); |
165
|
|
|
|
166
|
|
|
$backUrl = $this->getBackUrl($request); |
167
|
|
|
|
168
|
|
View Code Duplication |
if ($createForm instanceof FormInterface) { |
|
|
|
|
169
|
|
|
try { |
170
|
|
|
$createForm->validateForm($request, $model); |
171
|
|
|
|
172
|
|
|
if ($createForm->saveForm($request, $model) === false) { |
173
|
|
|
return redirect()->back()->with([ |
174
|
|
|
'_redirectBack' => $backUrl, |
175
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
176
|
|
|
]); |
177
|
|
|
} |
178
|
|
|
} catch (ValidationException $exception) { |
179
|
|
|
return redirect()->back() |
180
|
|
|
->withErrors($exception->validator) |
181
|
|
|
->withInput() |
182
|
|
|
->with([ |
183
|
|
|
'_redirectBack' => $backUrl, |
184
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
185
|
|
|
]); |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
if ($nextAction == 'save_and_continue') { |
190
|
|
|
$newModel = $createForm->getModel(); |
191
|
|
|
$primaryKey = $newModel->getKeyName(); |
192
|
|
|
|
193
|
|
|
$redirectUrl = $model->getEditUrl($newModel->{$primaryKey}); |
194
|
|
|
$redirectPolicy = $model->getRedirect(); |
195
|
|
|
|
196
|
|
|
/* Make redirect when use in model config && Fix editable redirect */ |
197
|
|
|
if ($redirectPolicy->get('create') == 'display' || ! $model->isEditable($newModel)) { |
198
|
|
|
$redirectUrl = $model->getDisplayUrl(); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
$response = redirect()->to( |
202
|
|
|
$redirectUrl |
203
|
|
|
)->with([ |
204
|
|
|
'_redirectBack' => $backUrl, |
205
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
206
|
|
|
]); |
207
|
|
View Code Duplication |
} elseif ($nextAction == 'save_and_create') { |
|
|
|
|
208
|
|
|
$response = redirect()->to($model->getCreateUrl($request->except([ |
209
|
|
|
'_redirectBack', |
210
|
|
|
'_token', |
211
|
|
|
'url', |
212
|
|
|
'next_action', |
213
|
|
|
])))->with([ |
214
|
|
|
'_redirectBack' => $backUrl, |
215
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
216
|
|
|
]); |
217
|
|
|
} else { |
218
|
|
|
$response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl())); |
|
|
|
|
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
return $response->with('success_message', $model->getMessageOnCreate()); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param ModelConfigurationInterface $model |
226
|
|
|
* @param int $id |
227
|
|
|
* |
228
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
229
|
|
|
* |
230
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
231
|
|
|
*/ |
232
|
|
|
public function getEdit(ModelConfigurationInterface $model, $id) |
233
|
|
|
{ |
234
|
|
|
$item = $model->getRepository()->find($id); |
235
|
|
|
|
236
|
|
|
if (is_null($item) || ! $model->isEditable($item)) { |
237
|
|
|
abort(404); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
$this->registerBreadcrumb($model->getEditTitle(), $this->parentBreadcrumb); |
|
|
|
|
241
|
|
|
|
242
|
|
|
return $this->render($model, $model->fireEdit($id), $model->getEditTitle()); |
|
|
|
|
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param ModelConfigurationInterface $model |
247
|
|
|
* @param Request $request |
248
|
|
|
* @param int $id |
249
|
|
|
* |
250
|
|
|
* @return \Illuminate\Http\RedirectResponse |
251
|
|
|
* |
252
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
253
|
|
|
*/ |
254
|
|
|
public function postUpdate(ModelConfigurationInterface $model, Request $request, $id) |
255
|
|
|
{ |
256
|
|
|
/** @var FormInterface $editForm */ |
257
|
|
|
$editForm = $model->fireEdit($id); |
258
|
|
|
$item = $editForm->getModel(); |
259
|
|
|
|
260
|
|
|
if (is_null($item) || ! $model->isEditable($item)) { |
261
|
|
|
abort(404); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
$nextAction = $request->input('next_action'); |
265
|
|
|
|
266
|
|
|
$backUrl = $this->getBackUrl($request); |
267
|
|
|
|
268
|
|
View Code Duplication |
if ($editForm instanceof FormInterface) { |
|
|
|
|
269
|
|
|
try { |
270
|
|
|
$editForm->validateForm($request, $model); |
271
|
|
|
|
272
|
|
|
if ($editForm->saveForm($request, $model) === false) { |
273
|
|
|
return redirect()->back()->with([ |
274
|
|
|
'_redirectBack' => $backUrl, |
275
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
276
|
|
|
]); |
277
|
|
|
} |
278
|
|
|
} catch (ValidationException $exception) { |
279
|
|
|
return redirect()->back() |
280
|
|
|
->withErrors($exception->validator) |
281
|
|
|
->withInput() |
282
|
|
|
->with([ |
283
|
|
|
'_redirectBack' => $backUrl, |
284
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
285
|
|
|
]); |
286
|
|
|
} |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
$redirectPolicy = $model->getRedirect(); |
290
|
|
|
|
291
|
|
|
if ($nextAction == 'save_and_continue') { |
292
|
|
|
$response = redirect()->back()->with([ |
293
|
|
|
'_redirectBack' => $backUrl, |
294
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
295
|
|
|
]); |
296
|
|
|
|
297
|
|
|
if ($redirectPolicy->get('edit') == 'display') { |
298
|
|
|
$response = redirect()->to( |
299
|
|
|
$model->getDisplayUrl() |
300
|
|
|
)->with([ |
301
|
|
|
'_redirectBack' => $backUrl, |
302
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
303
|
|
|
]); |
304
|
|
|
} |
305
|
|
View Code Duplication |
} elseif ($nextAction == 'save_and_create') { |
|
|
|
|
306
|
|
|
$response = redirect()->to($model->getCreateUrl($request->except([ |
307
|
|
|
'_redirectBack', |
308
|
|
|
'_token', |
309
|
|
|
'url', |
310
|
|
|
'next_action', |
311
|
|
|
])))->with([ |
312
|
|
|
'_redirectBack' => $backUrl, |
313
|
|
|
'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
314
|
|
|
]); |
315
|
|
|
} else { |
316
|
|
|
$response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl())); |
|
|
|
|
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
return $response->with('success_message', $model->getMessageOnUpdate()); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* @param ModelConfigurationInterface $model |
324
|
|
|
* @param Request $request |
325
|
|
|
* |
326
|
|
|
* @return bool |
327
|
|
|
* |
328
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
329
|
|
|
*/ |
330
|
|
|
public function inlineEdit(ModelConfigurationInterface $model, Request $request) |
331
|
|
|
{ |
332
|
|
|
$field = $request->input('name'); |
333
|
|
|
$id = $request->input('pk'); |
334
|
|
|
$display = $model->fireDisplay(); |
335
|
|
|
$column = null; |
336
|
|
|
|
337
|
|
|
/* @var ColumnEditableInterface|null $column */ |
338
|
|
|
if (is_callable([$display, 'getColumns'])) { |
339
|
|
|
$column = $display->getColumns()->all()->filter(function ($column) use ($field) { |
340
|
|
|
return ($column instanceof ColumnEditableInterface) and $field == $column->getName(); |
|
|
|
|
341
|
|
|
})->first(); |
342
|
|
|
} else { |
343
|
|
|
if ($display instanceof DisplayTabbed) { |
344
|
|
|
foreach ($display->getTabs() as $tab) { |
345
|
|
|
$content = $tab->getContent(); |
346
|
|
|
|
347
|
|
View Code Duplication |
if ($content instanceof DisplayTable) { |
|
|
|
|
348
|
|
|
$column = $content->getColumns()->all()->filter(function ($column) use ($field) { |
349
|
|
|
return ($column instanceof ColumnEditableInterface) and $field == $column->getName(); |
|
|
|
|
350
|
|
|
})->first(); |
351
|
|
|
} |
352
|
|
|
if ($content instanceof FormElements) { |
353
|
|
|
foreach ($content->getElements() as $element) { |
354
|
|
|
|
355
|
|
|
//Return data-table if inside FormElements |
356
|
|
View Code Duplication |
if ($element instanceof DisplayTable) { |
|
|
|
|
357
|
|
|
$column = $element->getColumns()->all()->filter(function ($column) use ($field) { |
358
|
|
|
return ($column instanceof ColumnEditableInterface) and $field == $column->getName(); |
|
|
|
|
359
|
|
|
})->first(); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
//Try to find inline Editable in columns |
363
|
|
|
if ($element instanceof Column) { |
364
|
|
|
foreach ($element->getElements() as $columnElement) { |
365
|
|
View Code Duplication |
if ($columnElement instanceof DisplayTable) { |
|
|
|
|
366
|
|
|
$column = $columnElement->getColumns()->all()->filter(function ($column) use ($field) { |
367
|
|
|
return ($column instanceof ColumnEditableInterface) and $field == $column->getName(); |
|
|
|
|
368
|
|
|
})->first(); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
} |
375
|
|
|
} |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
if (is_null($column)) { |
379
|
|
|
abort(404); |
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
$repository = $model->getRepository(); |
383
|
|
|
$item = $repository->find($id); |
384
|
|
|
|
385
|
|
|
if (is_null($item) || ! $model->isEditable($item)) { |
386
|
|
|
abort(404); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
$column->setModel($item); |
390
|
|
|
|
391
|
|
|
if ($model->fireEvent('updating', true, $item) === false) { |
392
|
|
|
return; |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
$column->save($request, $model); |
396
|
|
|
|
397
|
|
|
$model->fireEvent('updated', false, $item); |
398
|
|
|
} |
399
|
|
|
|
400
|
|
|
/** |
401
|
|
|
* @param ModelConfigurationInterface $model |
402
|
|
|
* @param int $id |
403
|
|
|
* |
404
|
|
|
* @return \Illuminate\Http\RedirectResponse |
405
|
|
|
* |
406
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
407
|
|
|
*/ |
408
|
|
View Code Duplication |
public function deleteDelete(ModelConfigurationInterface $model, Request $request, $id) |
|
|
|
|
409
|
|
|
{ |
410
|
|
|
$item = $model->getRepository()->find($id); |
411
|
|
|
|
412
|
|
|
if (is_null($item) || ! $model->isDeletable($item)) { |
413
|
|
|
abort(404); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
$model->fireDelete($id); |
417
|
|
|
|
418
|
|
|
if ($model->fireEvent('deleting', true, $item) === false) { |
419
|
|
|
return redirect()->back(); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
$model->getRepository()->delete($id); |
423
|
|
|
|
424
|
|
|
$model->fireEvent('deleted', false, $item); |
425
|
|
|
|
426
|
|
|
return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
|
|
|
|
427
|
|
|
->with('success_message', $model->getMessageOnDelete()); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
/** |
431
|
|
|
* @param ModelConfigurationInterface $model |
432
|
|
|
* @param Request $request |
433
|
|
|
* @param int $id |
434
|
|
|
* |
435
|
|
|
* @return \Illuminate\Http\RedirectResponse |
436
|
|
|
* |
437
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
438
|
|
|
*/ |
439
|
|
View Code Duplication |
public function deleteDestroy(ModelConfigurationInterface $model, Request $request, $id) |
|
|
|
|
440
|
|
|
{ |
441
|
|
|
if (! $model->isRestorableModel()) { |
442
|
|
|
abort(404); |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
$item = $model->getRepository()->findOnlyTrashed($id); |
446
|
|
|
|
447
|
|
|
if (is_null($item) || ! $model->isRestorable($item)) { |
448
|
|
|
abort(404); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
$model->fireDestroy($id); |
452
|
|
|
|
453
|
|
|
if ($model->fireEvent('destroying', true, $item) === false) { |
454
|
|
|
return redirect()->back(); |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
$model->getRepository()->forceDelete($id); |
458
|
|
|
|
459
|
|
|
$model->fireEvent('destroyed', false, $item); |
460
|
|
|
|
461
|
|
|
return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
|
|
|
|
462
|
|
|
->with('success_message', $model->getMessageOnDestroy()); |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* @param ModelConfigurationInterface|ModelConfiguration $model |
467
|
|
|
* @param Request $request |
468
|
|
|
* @param int $id |
469
|
|
|
* |
470
|
|
|
* @return \Illuminate\Http\RedirectResponse |
471
|
|
|
* |
472
|
|
|
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
473
|
|
|
*/ |
474
|
|
View Code Duplication |
public function postRestore(ModelConfigurationInterface $model, Request $request, $id) |
|
|
|
|
475
|
|
|
{ |
476
|
|
|
if (! $model->isRestorableModel()) { |
477
|
|
|
abort(404); |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
$item = $model->getRepository()->findOnlyTrashed($id); |
481
|
|
|
|
482
|
|
|
if (is_null($item) || ! $model->isRestorable($item)) { |
483
|
|
|
abort(404); |
484
|
|
|
} |
485
|
|
|
|
486
|
|
|
$model->fireRestore($id); |
487
|
|
|
|
488
|
|
|
if ($model->fireEvent('restoring', true, $item) === false) { |
489
|
|
|
return redirect()->back(); |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
$model->getRepository()->restore($id); |
493
|
|
|
|
494
|
|
|
$model->fireEvent('restored', false, $item); |
495
|
|
|
|
496
|
|
|
return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
|
|
|
|
497
|
|
|
->with('success_message', $model->getMessageOnRestore()); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* @param ModelConfigurationInterface $model |
502
|
|
|
* @param Renderable|string $content |
503
|
|
|
* @param string|null $title |
504
|
|
|
* |
505
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
506
|
|
|
*/ |
507
|
|
|
public function render(ModelConfigurationInterface $model, $content, $title = null) |
508
|
|
|
{ |
509
|
|
|
if ($content instanceof Renderable) { |
510
|
|
|
$content = $content->render(); |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
if (is_null($title)) { |
514
|
|
|
$title = $model->getTitle(); |
515
|
|
|
} |
516
|
|
|
|
517
|
|
|
return $this->admin->template()->view('_layout.inner') |
|
|
|
|
518
|
|
|
->with('title', $title) |
519
|
|
|
->with('content', $content) |
520
|
|
|
->with('breadcrumbKey', $this->parentBreadcrumb); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
/** |
524
|
|
|
* @param Renderable|string $content |
525
|
|
|
* @param string|null $title |
526
|
|
|
* |
527
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
528
|
|
|
*/ |
529
|
|
|
public function renderContent($content, $title = null) |
530
|
|
|
{ |
531
|
|
|
if ($content instanceof Renderable) { |
532
|
|
|
$content = $content->render(); |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
return $this->admin->template()->view('_layout.inner') |
|
|
|
|
536
|
|
|
->with('title', $title) |
537
|
|
|
->with('content', $content) |
538
|
|
|
->with('breadcrumbKey', $this->parentBreadcrumb); |
539
|
|
|
} |
540
|
|
|
|
541
|
|
|
/** |
542
|
|
|
* @param Request $request |
543
|
|
|
* |
544
|
|
|
* @return null|string |
545
|
|
|
*/ |
546
|
|
|
protected function getBackUrl(Request $request) |
547
|
|
|
{ |
548
|
|
|
if (($backUrl = $request->input('_redirectBack')) == \URL::previous()) { |
549
|
|
|
$backUrl = null; |
550
|
|
|
$request->merge(['_redirectBack' => $backUrl]); |
551
|
|
|
} |
552
|
|
|
|
553
|
|
|
return $backUrl; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
public function getWildcard() |
557
|
|
|
{ |
558
|
|
|
abort(404); |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* @param string $title |
563
|
|
|
* @param string $parent |
564
|
|
|
*/ |
565
|
|
|
protected function registerBreadcrumb($title, $parent) |
566
|
|
|
{ |
567
|
|
|
$this->breadcrumbs->register('render', function ($breadcrumbs) use ($title, $parent) { |
568
|
|
|
$breadcrumbs->parent($parent); |
569
|
|
|
$breadcrumbs->push($title); |
570
|
|
|
}); |
571
|
|
|
|
572
|
|
|
$this->parentBreadcrumb = 'render'; |
573
|
|
|
} |
574
|
|
|
} |
575
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.