File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/Shop/Categories/CategoryController.php
<?php
namespace App\KommaApp\Shop\Categories;
use App\Http\Controllers\Controller;
use App\KommaApp\Shop\Categories\CategoryService;
use App\KommaApp\Shop\Categories\Models\Category;
use Illuminate\Database\Eloquent\Collection;
class CategoryController extends Controller
{
private $pagePrefix = 'shop.pages.categories.';
protected $categoryService;
public function __construct(CategoryService $categoryService)
{
parent::__construct();
$this->categoryService = $categoryService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->pageService->getPageByCodeName('products');
$page->translation = $this->decodeDynamicContent( $page->translation );
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
// Return view
return \View::make($this->pagePrefix.'index',[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes
]);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function filters()
{
$filters = request('filters');
var_dump('Filter posts with these filters:');
$page = $this->pageService->getPageByCodeName('categories');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
// Return view
return \View::make($this->pagePrefix.'index',[
'page' => $page,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes,
]);
}
/**
* @param Page $page
* @return \Illuminate\Contracts\View\View
*/
public function show(Category $category)
{
$reCategoryService = app()->make(ReCategoryService::class);
$category = $reCategoryService->getCategory($category->id, true);
if(!empty($category->translation->description)) {
$category->translation = $this->decodeDynamicContent($category->translation);
}
$page = $this->pageService->getPageByCodeName('products');
$otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $category);
//If doesn't have children, then load the product on the category
if($category->children->isEmpty()) {
$category->load('getProducts');
$subCategories = null;
}else {
$subCategories = Collection::make($category->children);
// $subCategories->load('getProductsLimited');
$subCategories->load('getProducts');
}
// Return view
return \View::make($this->pagePrefix.'show',[
'page' => $page,
'category' => $category,
'subCategories' => $subCategories,
'links' => $this->links,
'otherLanguages' => $otherLanguageRoutes
]);
}
}