File: D:/HostingSpaces/SBogers10/slenders.komma.pro/app/Komma/Pages/PageController.php
<?php
namespace App\Komma\Pages;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
final class PageController extends Controller
{
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Page $page)
{
// Get the page through the set links if translation isnt defined
if(!isset($page->translation)) $page = $this->links->{$page->code_name}->node;
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($page->translation);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
// Try to set the view to the code name template
// Else set to default
$view = 'site.templates.' . $page->code_name;
if( ! view()->exists($view)) $view = 'site.templates.default';
// Prepare view
$view = view($view,[
'components' => $components,
'links' => $this->links,
'languageMenu' => $languageMenu,
'page' => $page,
]);
// If code_name is home we use the own view function
if($page->code_name == 'home') return $this->home($view, $components);
return $view;
}
private function home($view, $components) {
// Find if there is a Monthly Must Have Component
$mmhComponents = $components->where('componentTypeCodeName', '=', 'mmh');
if($mmhComponents->isEmpty()) return $view;
// Add add it too the view
return $view->with([
'mmhCta' => $mmhComponents->first()->mmh
]);
}
}