File: D:/HostingSpaces/Lacom/lacom.nl/app/KommaApp/Pages/PageController.php
<?php
namespace App\KommaApp\Pages;
use App\Http\Controllers\Controller;
use App\KommaApp\Pages\Models\Page;
class PageController extends Controller
{
private $pagePrefix = 'pages.';
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Page $page)
{
// Load translation by eager loading
$page->load( 'translation');
// Check if given Page belongs to the set site
if($page->site_id != \App::getSite()->id) throw abort(404);
$this->pageService->generateBreadcrumbTree($page, $this->links);
// Get the route in other languages for menu and meta title
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
$page->translation = $this->decodeDynamicContent( $page->translation );
$view = $this->getPageView($page);
// Return view
return \View::make($view,[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes,
]);
}
/**
* Get the view for the page
*
* @param Page $page
* @return string
*/
private function getPageView(Page $page){
// Set view for direct children of the group pages
if( $page->depth == 3 && $page->breadcrumbTree[1]->node->node->code_name === 'group'){
$view = $this->baseViewPath.$this->pagePrefix.'company';
// Determine the reference used on the page because we always want one
$this->referenceService->determineReferenceAndShareWithViews($page, false);
// If the view exists return it
if( \View::exists($view)) return $view;
}
// Try if the page has it's own view (by code_name)
$view = $this->baseViewPath.$this->pagePrefix. $page->code_name;
if($page->code_name == 'about') $this->referenceService->determineReferenceAndShareWithViews($page, false);
// If the view exists return it
if( \View::exists($view)) return $view;
// Else return the default
else return $this->baseViewPath.$this->pagePrefix. 'default';
}
}