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/deensekroon.komma-mediadesign.nl/wwwroot/App/Brands/BrandController.php
<?php


namespace App\Brands;


include_once($_SERVER['DOCUMENT_ROOT'] . '/App/Views/Brands/BrandDetail.php');
include_once($_SERVER['DOCUMENT_ROOT'] . '/App/Views/Brands/BrandOverview.php');


use App\Products\ProductRepository;
use App\Views\Brands\BrandDetail;
use App\Views\Brands\BrandOverview;

class BrandController
{
    private $brandRepo;
    private $productRepo;

    /**
     * CategoryController constructor.
     */
    public function __construct()
    {
        $this->brandRepo = new BrandRepository();
        $this->productRepo = new ProductRepository();
    }

    /**
     *
     */
    public function index()
    {
        $brands = $this->brandRepo->brands();

        $view = new BrandOverview();
        $view->create($brands);

        return $view->render();
    }

    /**
     * Show brand with products
     * @param $id
     * @return string
     */
    public function show($id)
    {
        // Get brand
        if( ! $brand = $this->brandRepo->brand($id)) return false;

        // Get brand products
        $products = $this->productRepo->productsByBrandId($id);

        // Create view
        $view = new BrandDetail();
        $view->create($brand, $products);

        // Render view
        return $view->render();
    }
}