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