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'
]);
}
}