HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/brameda/brameda.nl/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\Servicepoints\Models\Servicepoint;
use App\Komma\WebsiteConfig\Model\WebsiteConfig;

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;

        /** @var ComponentService $componentService */
        $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);

        $view = 'site.templates.' . $page->code_name;
        if( ! view()->exists($view)) $view = 'site.templates.default';

        // split the Hero images from the "normal" page images
        list($documents, $heroDocuments) = $page->translation->documents->partition(function ($document) {
            return $document->key == 'Documents-pages';
        });
        $page->documents = $documents;

        // fill the page hero object
        $heroButton = Button::where('id', $page->translation->hero_button_id)->with('translation')->first();
        $page->hero = (object)[
            'documents' => $heroDocuments,
            'active' => $page->translation->hero_active,
            'title' => $page->translation->hero_title,
            'description' => $page->translation->hero_description,
            'buttons' => !empty($heroButton) ? $heroButton : null,
        ];

        // fill the heroImage object (currently only used on the homepage
        $homeHeroesConfig = WebsiteConfig::where('code_name', '=', 'home_heroes')->first();
        $homeHeroTitle = WebsiteConfig::where('code_name', '=', 'home_hero_title')->first();
        $page->heroImage = (object)[
            'documents' => collect(),
            'caption' => ''
        ];
        if($homeHeroesConfig) {
            $page->heroImage = (object)[
                'documents' => $homeHeroesConfig->documents,
                'caption' => $homeHeroTitle->value
            ];
        }

        $this->pageService->setSharebleVariables($page->servicepoint_id, $page->cta_button_id, $page->cta_heading);

        //Get the "discover more" page code names.
        $discover_more_page_codenames = $page->discoverPages()->get()->map(function(Page $page) {
            return $page->code_name;
        })->toArray();

        // Return view
        return view($view,[
            'components' => $components,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
            'discover_page_codenames' => $discover_more_page_codenames,
            'page' => $page,
        ]);
    }
}