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/ste.komma.pro/app/Products/ProductController.php
<?php

namespace App\Products;

use App\Base\Controller;
use App\Components\ComponentService;
use App\Products\Models\Product;

final class ProductController extends Controller
{
    private $productService;

    public function __construct(ProductService $productService)
    {
        parent::__construct();
        $this->productService = $productService;
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->links->products->node;

        // NOTE: Products are implement through the ProductComposer,
        //       because they are already needed on Home and Footer in the same   way

        // Make language menu for given page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);

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

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


    /**
     * @param Product $product
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Product $product)
    {
        $product->load('translation','translations', 'banners');

        $products = $this->productService->getNextProducts($product);

        // Make language menu for given page
        $page = $this->links->products->node;
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->products, $this->links->home);
        $this->pageService->extendLanguageMenuWithResource($languageMenu, $product);

        if(isset($product->banners) && $product->banners->isNotEmpty()) $product->banner = $product->banners->first();
        else $product->banner = null;

        // Return view
        return view('templates.products_show',[
            'page' => $page,
            'products' => $products,
            'product' => $product,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
        ]);
    }

}