File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Pages/PageController.php
<?php
namespace App\Komma\Pages;
use App\Komma\Base\Controller;
use App\Komma\Buttons\Models\Button;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
use App\Komma\Projects\ProjectService;
use App\Komma\Servicepoints\Models\Servicepoint;
final class PageController extends Controller
{
private $projectService;
public function __construct()
{
parent::__construct();
$this->projectService = app(ProjectService::class);
}
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Page $page)
{
// Uncomment this line to test the under construction page
// return view('site.templates.underConstruction');
// Get the page through the set links if translation isnt defined
if(!isset($page->translation)) $page = $this->links->{$page->code_name}->node;
// By default get the first servicepoint
$servicepoint = Servicepoint::first();
// Get the chosen servicepoint for the page
if(!empty($page->translation->servicepoint_id)) $servicepoint = Servicepoint::find($page->translation->servicepoint_id);
$heroButton = null;
if(!empty($page->translation->hero_button_id)) $heroButton = Button::where('id', $page->translation->hero_button_id)->with('translation')->first();
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($page->translation);
$featuredProjects = $this->projectService->getFeaturedProjects()->get();
$children = $page->findChildren();
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$view = 'site.templates.' . $page->code_name;
if( ! view()->exists($view)) $view = 'site.templates.default';
// Return view
return view($view,[
'components' => $components,
'links' => $this->links,
'languageMenu' => $languageMenu,
'page' => $page,
'children' => $children,
'featuredProjects' => $featuredProjects,
'servicepoint' => $servicepoint,
'heroButton' => !empty($heroButton) ? $heroButton : null,
]);
}
public function offline()
{
return view('site.templates.offline');
}
}