Total Complexity | 120 |
Total Lines | 731 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AdminController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AdminController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class AdminController extends Controller |
||
22 | { |
||
23 | /** |
||
24 | * @var \DaveJamesMiller\Breadcrumbs\Manager |
||
25 | */ |
||
26 | protected $breadcrumbs; |
||
27 | |||
28 | /** |
||
29 | * @var |
||
30 | */ |
||
31 | protected $breadCrumbsData; |
||
32 | |||
33 | /** |
||
34 | * @var AdminInterface |
||
35 | */ |
||
36 | protected $admin; |
||
37 | |||
38 | /** |
||
39 | * @var |
||
40 | */ |
||
41 | private $parentBreadcrumb = 'home'; |
||
42 | |||
43 | /** |
||
44 | * @var Application |
||
45 | */ |
||
46 | public $app; |
||
47 | |||
48 | /** |
||
49 | * @var |
||
50 | */ |
||
51 | protected $envPolicy; |
||
52 | |||
53 | /** |
||
54 | * AdminController constructor. |
||
55 | * |
||
56 | * @param Request $request |
||
57 | * @param AdminInterface $admin |
||
58 | * @param Application $application |
||
59 | */ |
||
60 | public function __construct(Request $request, AdminInterface $admin, Application $application) |
||
61 | { |
||
62 | $this->app = $application; |
||
63 | $this->admin = $admin; |
||
64 | $this->breadcrumbs = $admin->template()->breadcrumbs(); |
||
65 | |||
66 | if ($this->envPolicy = config('sleeping_owl.env_editor_policy')) { |
||
67 | $this->envPolicy = new $this->envPolicy; |
||
68 | } |
||
69 | |||
70 | $admin->navigation()->setCurrentUrl($request->getUri()); |
||
|
|||
71 | |||
72 | if (! $this->breadcrumbs->exists('home')) { |
||
73 | $this->breadcrumbs->register('home', function (Generator $breadcrumbs) { |
||
74 | $breadcrumbs->push(trans('sleeping_owl::lang.dashboard'), route('admin.dashboard')); |
||
75 | }); |
||
76 | } |
||
77 | |||
78 | $this->breadCrumbsData = []; |
||
79 | |||
80 | if ($currentPage = $admin->navigation()->getCurrentPage()) { |
||
81 | foreach ($currentPage->getPathArray() as $page) { |
||
82 | $this->breadCrumbsData[] = [ |
||
83 | 'id' => $page['id'], |
||
84 | 'title' => $page['title'], |
||
85 | 'url' => $page['url'], |
||
86 | 'parent' => $this->parentBreadcrumb, |
||
87 | ]; |
||
88 | |||
89 | $this->parentBreadcrumb = $page['id']; |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getParentBreadcrumb() |
||
98 | { |
||
99 | return $this->parentBreadcrumb; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @param string $parentBreadcrumb |
||
104 | */ |
||
105 | public function setParentBreadcrumb($parentBreadcrumb) |
||
106 | { |
||
107 | $this->parentBreadcrumb = $parentBreadcrumb; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
112 | */ |
||
113 | public function getDashboard() |
||
114 | { |
||
115 | return $this->renderContent( |
||
116 | $this->admin->template()->view('dashboard'), |
||
117 | trans('sleeping_owl::lang.dashboard') |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
123 | */ |
||
124 | public function getEnvEditor() |
||
125 | { |
||
126 | $envFile = app()->environmentFilePath(); |
||
127 | $envContent = collect(parse_ini_file($envFile, false, INI_SCANNER_RAW)); |
||
128 | |||
129 | /** |
||
130 | * Use filter masks. |
||
131 | * @param $key |
||
132 | * @return bool |
||
133 | */ |
||
134 | $envContent = $envContent->filter(function ($value, $key) { |
||
135 | return ! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key); |
||
136 | }); |
||
137 | |||
138 | $envContent = $envContent->filter(function ($value, $key) { |
||
139 | return $this->validatePolicy('display', $key); |
||
140 | }); |
||
141 | |||
142 | $envContent = $envContent->map(function ($value, $key) { |
||
143 | return (object)[ |
||
144 | 'value' => $value, |
||
145 | 'editable' => $this->validatePolicy('edit', $key), |
||
146 | 'deletable' => $this->validatePolicy('delete', $key), |
||
147 | ]; |
||
148 | }); |
||
149 | |||
150 | return $this->renderContent( |
||
151 | $this->admin->template()->view('env_editor', ['data' => $envContent]), |
||
152 | trans('sleeping_owl::lang.env_editor.title') |
||
153 | ); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * @param $permission |
||
158 | * @param $key |
||
159 | * @return bool |
||
160 | */ |
||
161 | protected function validatePolicy($permission, $key) |
||
162 | { |
||
163 | return ($this->envPolicy && ((method_exists($this->envPolicy, $permission) |
||
164 | && $this->envPolicy->$permission(\Auth::user(), $key) !== false))) |
||
165 | || ! method_exists($this->envPolicy, $permission) || ! $this->envPolicy || $this->validateBeforePolicy($key); |
||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @param $key |
||
170 | * @return bool |
||
171 | */ |
||
172 | protected function validateBeforePolicy($key) |
||
173 | { |
||
174 | return ($this->envPolicy && (method_exists($this->envPolicy, 'before')) |
||
175 | && $this->envPolicy->before(\Auth::user(),$key) == true) |
||
176 | || ! method_exists($this->envPolicy,'before') || ! $this->envPolicy; |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @param Request $request |
||
181 | * @return \Illuminate\Http\RedirectResponse |
||
182 | */ |
||
183 | public function postEnvEditor(Request $request) |
||
184 | { |
||
185 | $envFile = app()->environmentFilePath(); |
||
186 | $envContent = collect(parse_ini_file($envFile, false, INI_SCANNER_RAW)); |
||
187 | |||
188 | $requestContent = collect($request->input('variables')); |
||
189 | $removeContent = collect(); |
||
190 | |||
191 | foreach ($envContent as $key => $value) { |
||
192 | if (! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key)) { |
||
193 | if ($requestContent->has($key)) { |
||
194 | if ($this->validatePolicy('edit', $key)) { |
||
195 | $envContent[$key] = $requestContent[$key]['value']; |
||
196 | } |
||
197 | $requestContent->forget($key); |
||
198 | } else { |
||
199 | $envContent->forget($key); |
||
200 | $removeContent->put($key, null); |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | |||
205 | foreach ($requestContent as $key => $value) { |
||
206 | if (! in_array($key, config('sleeping_owl.env_editor_excluded_keys')) && ! $this->filterKey($key) |
||
207 | && $this->validatePolicy('create', $key)) { |
||
208 | $this->writeEnvData($key, $value['value'], 1); |
||
209 | } |
||
210 | $requestContent->forget($key); |
||
211 | } |
||
212 | |||
213 | foreach ($removeContent as $key => $value) { |
||
214 | if ($this->validatePolicy('delete', $key)) { |
||
215 | $this->writeEnvData($key); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | foreach ($envContent as $key => $value) { |
||
220 | $this->writeEnvData($key, $value); |
||
221 | } |
||
222 | |||
223 | return redirect()->back()->with('success_message', 'Env Updated'); |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * @param $key |
||
228 | * @return bool |
||
229 | */ |
||
230 | public function filterKey($key) |
||
231 | { |
||
232 | foreach (config('sleeping_owl.env_editor_excluded_keys') as $val) { |
||
233 | if (strpos($val, '*') !== false) { |
||
234 | $val = str_replace('*', '', $val); |
||
235 | if (strpos($key, $val) !== false) { |
||
236 | return true; |
||
237 | } |
||
238 | } |
||
239 | } |
||
240 | |||
241 | return false; |
||
242 | } |
||
243 | |||
244 | /** |
||
245 | * @param $key |
||
246 | * @param null $data |
||
247 | * @param bool $new |
||
248 | * @return bool |
||
249 | */ |
||
250 | public function writeEnvData($key, $data = null, $new = null) |
||
251 | { |
||
252 | $envFile = app()->environmentFilePath(); |
||
253 | $str = file_get_contents($envFile); |
||
254 | |||
255 | if (is_null($data)) { |
||
256 | $str = preg_replace("/$key=.*/m", '', $str); |
||
257 | file_put_contents($envFile, $str); |
||
258 | |||
259 | return false; |
||
260 | } |
||
261 | |||
262 | if (is_null($new)) { |
||
263 | $str = preg_replace("/$key=.*/m", "$key=$data", $str); |
||
264 | file_put_contents($envFile, $str); |
||
265 | |||
266 | return false; |
||
267 | } |
||
268 | |||
269 | $str = $str."\r\n$key=$data"; |
||
270 | file_put_contents($envFile, $str); |
||
271 | |||
272 | return true; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * @param ModelConfigurationInterface $model |
||
277 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
278 | * @throws \DaveJamesMiller\Breadcrumbs\Exception |
||
279 | */ |
||
280 | public function getDisplay(ModelConfigurationInterface $model) |
||
281 | { |
||
282 | if (! $model->isDisplayable()) { |
||
283 | abort(404); |
||
284 | } |
||
285 | |||
286 | $display = $model->fireDisplay(); |
||
287 | |||
288 | $this->registerBreadcrumbs($model); |
||
289 | |||
290 | return $this->render($model, $display); |
||
291 | } |
||
292 | |||
293 | /** |
||
294 | * @param ModelConfigurationInterface $model |
||
295 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
296 | * @throws \DaveJamesMiller\Breadcrumbs\Exception |
||
297 | */ |
||
298 | public function getCreate(ModelConfigurationInterface $model) |
||
299 | { |
||
300 | if (! $model->isCreatable()) { |
||
301 | abort(404); |
||
302 | } |
||
303 | |||
304 | $create = $model->fireCreate(); |
||
305 | |||
306 | $this->registerBreadcrumb($model->getCreateTitle(), $this->parentBreadcrumb); |
||
307 | $this->registerBreadcrumbs($model); |
||
308 | |||
309 | return $this->render($model, $create, $model->getCreateTitle()); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @param ModelConfigurationInterface $model |
||
314 | * @param Request $request |
||
315 | * |
||
316 | * @return \Illuminate\Http\RedirectResponse |
||
317 | */ |
||
318 | public function postStore(ModelConfigurationInterface $model, Request $request) |
||
319 | { |
||
320 | if (! $model->isCreatable()) { |
||
321 | abort(404); |
||
322 | } |
||
323 | |||
324 | $createForm = $model->fireCreate(); |
||
325 | $nextAction = $request->input('next_action'); |
||
326 | |||
327 | $backUrl = $this->getBackUrl($request); |
||
328 | |||
329 | if ($createForm instanceof FormInterface) { |
||
330 | try { |
||
331 | $createForm->validateForm($request, $model); |
||
332 | |||
333 | if ($createForm->saveForm($request, $model) === false) { |
||
334 | return redirect()->back()->with([ |
||
335 | '_redirectBack' => $backUrl, |
||
336 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
337 | ]); |
||
338 | } |
||
339 | } catch (ValidationException $exception) { |
||
340 | return redirect()->back() |
||
341 | ->withErrors($exception->validator) |
||
342 | ->withInput() |
||
343 | ->with([ |
||
344 | '_redirectBack' => $backUrl, |
||
345 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
346 | ]); |
||
347 | } |
||
348 | } |
||
349 | |||
350 | if ($nextAction == 'save_and_continue') { |
||
351 | $newModel = $createForm->getModel(); |
||
352 | $primaryKey = $newModel->getKeyName(); |
||
353 | |||
354 | $redirectUrl = $model->getEditUrl($newModel->{$primaryKey}); |
||
355 | $redirectPolicy = $model->getRedirect(); |
||
356 | |||
357 | /* Make redirect when use in model config && Fix editable redirect */ |
||
358 | if ($redirectPolicy->get('create') == 'display' || ! $model->isEditable($newModel)) { |
||
359 | $redirectUrl = $model->getDisplayUrl(); |
||
360 | } |
||
361 | |||
362 | $response = redirect()->to( |
||
363 | $redirectUrl |
||
364 | )->with([ |
||
365 | '_redirectBack' => $backUrl, |
||
366 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
367 | ]); |
||
368 | } elseif ($nextAction == 'save_and_create') { |
||
369 | $response = redirect()->to($model->getCreateUrl($request->except([ |
||
370 | '_redirectBack', |
||
371 | '_token', |
||
372 | 'url', |
||
373 | 'next_action', |
||
374 | ])))->with([ |
||
375 | '_redirectBack' => $backUrl, |
||
376 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
377 | ]); |
||
378 | } else { |
||
379 | $response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl())); |
||
380 | } |
||
381 | |||
382 | return $response->with('success_message', $model->getMessageOnCreate()); |
||
383 | } |
||
384 | |||
385 | /** |
||
386 | * @param ModelConfigurationInterface $model |
||
387 | * @param $id |
||
388 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
389 | * @throws \DaveJamesMiller\Breadcrumbs\Exception |
||
390 | */ |
||
391 | public function getEdit(ModelConfigurationInterface $model, $id) |
||
392 | { |
||
393 | $item = $model->getRepository()->find($id); |
||
394 | |||
395 | if (is_null($item) || ! $model->isEditable($item)) { |
||
396 | abort(404); |
||
397 | } |
||
398 | |||
399 | $this->registerBreadcrumb($model->getEditTitle($item), $this->parentBreadcrumb); |
||
400 | |||
401 | $edit = $model->fireEdit($id); |
||
402 | |||
403 | $this->registerBreadcrumbs($model); |
||
404 | |||
405 | return $this->render($model, $edit, $model->getEditTitle($item)); |
||
406 | } |
||
407 | |||
408 | /** |
||
409 | * @param ModelConfigurationInterface $model |
||
410 | * @param Request $request |
||
411 | * @param int $id |
||
412 | * |
||
413 | * @return \Illuminate\Http\RedirectResponse |
||
414 | * |
||
415 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
416 | */ |
||
417 | public function postUpdate(ModelConfigurationInterface $model, Request $request, $id) |
||
418 | { |
||
419 | /** @var FormInterface $editForm */ |
||
420 | $editForm = $model->fireEdit($id); |
||
421 | $item = $editForm->getModel(); |
||
422 | |||
423 | if (is_null($item) || ! $model->isEditable($item)) { |
||
424 | abort(404); |
||
425 | } |
||
426 | |||
427 | $nextAction = $request->input('next_action'); |
||
428 | |||
429 | $backUrl = $this->getBackUrl($request); |
||
430 | |||
431 | if ($editForm instanceof FormInterface) { |
||
432 | try { |
||
433 | $editForm->validateForm($request, $model); |
||
434 | |||
435 | if ($editForm->saveForm($request, $model) === false) { |
||
436 | return redirect()->back()->with([ |
||
437 | '_redirectBack' => $backUrl, |
||
438 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
439 | ]); |
||
440 | } |
||
441 | } catch (ValidationException $exception) { |
||
442 | return redirect()->back() |
||
443 | ->withErrors($exception->validator) |
||
444 | ->withInput() |
||
445 | ->with([ |
||
446 | '_redirectBack' => $backUrl, |
||
447 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
448 | ]); |
||
449 | } |
||
450 | } |
||
451 | |||
452 | $redirectPolicy = $model->getRedirect(); |
||
453 | |||
454 | if ($nextAction == 'save_and_continue') { |
||
455 | $response = redirect()->back()->with([ |
||
456 | '_redirectBack' => $backUrl, |
||
457 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
458 | ]); |
||
459 | |||
460 | if ($redirectPolicy->get('edit') == 'display') { |
||
461 | $response = redirect()->to( |
||
462 | $model->getDisplayUrl() |
||
463 | )->with([ |
||
464 | '_redirectBack' => $backUrl, |
||
465 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
466 | ]); |
||
467 | } |
||
468 | } elseif ($nextAction == 'save_and_create') { |
||
469 | $response = redirect()->to($model->getCreateUrl($request->except([ |
||
470 | '_redirectBack', |
||
471 | '_token', |
||
472 | 'url', |
||
473 | 'next_action', |
||
474 | ])))->with([ |
||
475 | '_redirectBack' => $backUrl, |
||
476 | 'sleeping_owl_tab_id' => $request->get('sleeping_owl_tab_id') ?: null, |
||
477 | ]); |
||
478 | } else { |
||
479 | $response = redirect()->to($request->input('_redirectBack', $model->getDisplayUrl())); |
||
480 | } |
||
481 | |||
482 | return $response->with('success_message', $model->getMessageOnUpdate()); |
||
483 | } |
||
484 | |||
485 | /** |
||
486 | * @param ModelConfigurationInterface $model |
||
487 | * @param Request $request |
||
488 | * |
||
489 | * @return bool |
||
490 | * |
||
491 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
492 | */ |
||
493 | public function inlineEdit(ModelConfigurationInterface $model, Request $request) |
||
563 | } |
||
564 | |||
565 | /** |
||
566 | * @param ModelConfigurationInterface $model |
||
567 | * @param Request $request |
||
568 | * @param int $id |
||
569 | * @return \Illuminate\Http\RedirectResponse |
||
570 | */ |
||
571 | public function deleteDelete(ModelConfigurationInterface $model, Request $request, $id) |
||
572 | { |
||
573 | $item = $model->getRepository()->find($id); |
||
574 | |||
575 | if (is_null($item) || ! $model->isDeletable($item)) { |
||
576 | abort(404); |
||
577 | } |
||
578 | |||
579 | $model->fireDelete($id); |
||
580 | |||
581 | if ($model->fireEvent('deleting', true, $item, $request) === false) { |
||
582 | return redirect()->back(); |
||
583 | } |
||
584 | |||
585 | $model->getRepository()->delete($id); |
||
586 | |||
587 | $model->fireEvent('deleted', false, $item, $request); |
||
588 | |||
589 | return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
||
590 | ->with('success_message', $model->getMessageOnDelete()); |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * @param ModelConfigurationInterface $model |
||
595 | * @param Request $request |
||
596 | * @param int $id |
||
597 | * |
||
598 | * @return \Illuminate\Http\RedirectResponse |
||
599 | * |
||
600 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
601 | */ |
||
602 | public function deleteDestroy(ModelConfigurationInterface $model, Request $request, $id) |
||
603 | { |
||
604 | if (! $model->isRestorableModel()) { |
||
605 | abort(404); |
||
606 | } |
||
607 | |||
608 | $item = $model->getRepository()->findOnlyTrashed($id); |
||
609 | |||
610 | if (is_null($item) || ! $model->isRestorable($item)) { |
||
611 | abort(404); |
||
612 | } |
||
613 | |||
614 | $model->fireDestroy($id); |
||
615 | |||
616 | if ($model->fireEvent('destroying', true, $item, $request) === false) { |
||
617 | return redirect()->back(); |
||
618 | } |
||
619 | |||
620 | $model->getRepository()->forceDelete($id); |
||
621 | |||
622 | $model->fireEvent('destroyed', false, $item, $request); |
||
623 | |||
624 | return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
||
625 | ->with('success_message', $model->getMessageOnDestroy()); |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * @param ModelConfigurationInterface|ModelConfiguration $model |
||
630 | * @param Request $request |
||
631 | * @param int $id |
||
632 | * |
||
633 | * @return \Illuminate\Http\RedirectResponse |
||
634 | * |
||
635 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
636 | */ |
||
637 | public function postRestore(ModelConfigurationInterface $model, Request $request, $id) |
||
638 | { |
||
639 | if (! $model->isRestorableModel()) { |
||
640 | abort(404); |
||
641 | } |
||
642 | |||
643 | $item = $model->getRepository()->findOnlyTrashed($id); |
||
644 | |||
645 | if (is_null($item) || ! $model->isRestorable($item)) { |
||
646 | abort(404); |
||
647 | } |
||
648 | |||
649 | $model->fireRestore($id); |
||
650 | |||
651 | if ($model->fireEvent('restoring', true, $item, $request) === false) { |
||
652 | return redirect()->back(); |
||
653 | } |
||
654 | |||
655 | $model->getRepository()->restore($id); |
||
656 | |||
657 | $model->fireEvent('restored', false, $item, $request); |
||
658 | |||
659 | return redirect($request->input('_redirectBack', back()->getTargetUrl())) |
||
660 | ->with('success_message', $model->getMessageOnRestore()); |
||
661 | } |
||
662 | |||
663 | /** |
||
664 | * @param ModelConfigurationInterface $model |
||
665 | * @param Renderable|string $content |
||
666 | * @param string|null $title |
||
667 | * |
||
668 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
669 | */ |
||
670 | public function render(ModelConfigurationInterface $model, $content, $title = null) |
||
671 | { |
||
672 | if ($content instanceof Renderable) { |
||
673 | $content = $content->render(); |
||
674 | } |
||
675 | |||
676 | if (is_null($title)) { |
||
677 | $title = $model->getTitle(); |
||
678 | } |
||
679 | |||
680 | return $this->admin->template()->view('_layout.inner') |
||
681 | ->with('title', $title) |
||
682 | ->with('content', $content) |
||
683 | ->with('breadcrumbKey', $this->parentBreadcrumb); |
||
684 | } |
||
685 | |||
686 | /** |
||
687 | * @param Renderable|string $content |
||
688 | * @param string|null $title |
||
689 | * |
||
690 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
691 | */ |
||
692 | public function renderContent($content, $title = null) |
||
693 | { |
||
694 | if ($content instanceof Renderable) { |
||
695 | $content = $content->render(); |
||
696 | } |
||
697 | |||
698 | return $this->admin->template()->view('_layout.inner') |
||
699 | ->with('title', $title) |
||
700 | ->with('content', $content) |
||
701 | ->with('breadcrumbKey', $this->parentBreadcrumb); |
||
702 | } |
||
703 | |||
704 | /** |
||
705 | * @param Request $request |
||
706 | * |
||
707 | * @return null|string |
||
708 | */ |
||
709 | protected function getBackUrl(Request $request) |
||
710 | { |
||
711 | if (($backUrl = $request->input('_redirectBack')) == \URL::previous()) { |
||
712 | $backUrl = null; |
||
713 | $request->merge(['_redirectBack' => $backUrl]); |
||
714 | } |
||
715 | |||
716 | return $backUrl; |
||
717 | } |
||
718 | |||
719 | public function getWildcard() |
||
720 | { |
||
721 | abort(404); |
||
722 | } |
||
723 | |||
724 | /** |
||
725 | * @param $title |
||
726 | * @param $parent |
||
727 | * @throws \DaveJamesMiller\Breadcrumbs\Exception |
||
728 | */ |
||
729 | protected function registerBreadcrumb($title, $parent) |
||
737 | } |
||
738 | |||
739 | /** |
||
740 | * @param ModelConfigurationInterface $model |
||
741 | * @throws \DaveJamesMiller\Breadcrumbs\Exception |
||
742 | */ |
||
743 | protected function registerBreadcrumbs(ModelConfigurationInterface $model) |
||
752 | }); |
||
753 | } |
||
754 | } |
||
755 | } |
||
756 | } |
||
757 |