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/Workshops/WorkshopController.php
<?php

namespace App\Komma\Workshops;

use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Pages\Models\Page;
use App\Komma\Workshops\Models\Workshop;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

final class WorkshopController extends Controller
{
    private $workshopService;
    private $workshopPaginationKey = 'workshopPagination';

    public function __construct(WorkshopService $workshopService)
    {
        parent::__construct();
        $this->workshopService = $workshopService;
    }

    /**
     *
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {

        $page = $this->pageService->getPage(request()->get('page_id'));

        // Get the linker model
        $linkerModel = $this->links->{$page->code_name};

        // Get the page through the linker model
        $page = $linkerModel->node;
        $parent = $this->links->{$page->getParent()->code_name};
        $parent->subnav = $this->pageService->getSubnav($parent->node, $this->links);

        $workshops = $this->workshopService->getWorkshopsByCategoryPaginated($parent->node);
        $workshops->withPath($linkerModel->route);

        $this->keepTrackOfPagination($this->workshopPaginationKey);

        $componentService = app(ComponentService::class);
        $components = $componentService->getViewComponents($page->translation);

        $preOverview = collect();

        if ($components->count() != 0) {
            $preOverview->push($components->shift());
        }

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


    /**
     * @param  Workshop  $workshop
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Workshop $workshop)
    {

        // Load the needed relations
        $workshop->load('translation', 'images');

        $page = $this->pageService->getPage(request()->get('page_id'));
        $parent = $this->links->{$page->getParent()->code_name};

        // Get the linker model
        $linkerModel = $this->links->{$page->code_name};

        // Get the page through the linker model
        $page = $linkerModel->node;

        $componentService = app(ComponentService::class);
        $components = $componentService->getViewComponents($workshop->translation);

        // Create previous route for better navigation UX
        $previousRoute = $this->createPreviousRoute($this->workshopPaginationKey, $linkerModel->route);

//        $otherWorkshops = $this->workshopService->getNextWorkshops($workshop);

        // Return view
        return view('site.templates.model_show', [
            'page'          => $page,
            'parent'      => $parent,
            'model'      => $workshop,
            'components'    => $components,
            'links'         => $this->links,
            'previousRoute' => $previousRoute,
            'formRoute' => $this->links->sign_up->route,
            'modelType' => 'workshops'
        ]);
    }


}