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/SBogers10/inzigd.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;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;

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);

        // Special function for pages with children
        if(in_array($page->code_name, ['teaching', 'enterprising'])) return $this->childrenIndex($page, $components);

        // Special function for talent scan pages
        if( Str::endsWith($page->code_name, '_scan')) return $this->scan($page, $components);

        // Overrule random styling to set
        if($page->code_name == 'interview_success') view()->share('styling', 'u-bar');

        // Check if specific template exist
        $view = 'site.templates.'. $page->code_name;
        if( ! view()->exists($view)) $view = 'site.templates.default';

        if(in_array($page->code_name, ['interview', 'sign_up'])) $view = 'site.templates.model_form';
        if(in_array($page->code_name, ['interview_success', 'sign_up_success'])) $view = 'site.templates.model_form_success';

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

    private function scan(Page $page, $components) {

        $parent = $this->links->{$page->getParent()->code_name};
        $parent->subnav = $this->pageService->getSubnav($parent->node, $this->links);

        // Return view
        return view('site.templates.scan',[
            'page' => $page,
            'parent' => $parent,
            'components' => $components,
            'links' => $this->links,
        ]);
    }

    private function childrenIndex(Page $page, $components)
    {

        $subPages = Collection::make([]);
        foreach ($page->findChildren() as $child){
            $subPages->push($this->links->{$child->code_name}->node);
        }

        // Load images
        $subPages->load('images');

        // Return view
        return view('site.templates.subPagesOverview',[
            'page' => $page,
            'subPages' => $subPages,
            'components' => $components,
            'links' => $this->links,
        ]);

    }

}