File: D:/HostingSpaces/SBogers10/komma.pro/app/KommaApp/Services/ServiceController.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 18/05/17
* Time: 21:59
*/
namespace App\KommaApp\Services;
use App\Http\Controllers\Controller;
use App\KommaApp\Blocks\BlockService;
use Illuminate\Support\Facades\View;
use DaveJamesMiller\Breadcrumbs\Facade as Breadcrumbs;
class ServiceController extends Controller
{
/**
* @var ServiceService
*/
protected $serviceService;
/**
* @var BlockService
*/
private $blockService;
public function __construct()
{
parent::__construct();
$this->serviceService = app(ServiceService::class);
$this->blockService = app(BlockService::class);
$this->blockService->setSubFolder('services');
}
/**
* Show all services
*/
public function index()
{
// Fetch all services
$services = $this->serviceService->all();
// Render breadcrumb if exists
if( ! $breadcrumb = Breadcrumbs::renderIfExists('services')) $breadcrumb = false;
return View::make('site.pages.services',[
'namespace' => 'services',
'services' => $services,
'breadcrumb' => $breadcrumb
]);
}
/**
* Show a service detail page
*
* @param $slug
* @return
*/
public function show($slug)
{
// Find service
if( ! $service = $this->serviceService->serviceBySlug($slug)) \App::abort(404);
// Find next service
if( ! $nextService = $this->serviceService->nextService($service)) $nextService = false;
// Render breadcrumb if exists
if( ! $breadcrumb = Breadcrumbs::renderIfExists('service.'.$service->slug)) $breadcrumb = false;
// Decode dynamic blocks
$service->blocks = $this->blockService->decode($service->translation->description);
$view = 'site.pages._service';
if($service->use_new_layout) $view = 'site.pages.service';
// if(in_array($service->code_name, ['website', 'webshop', 'branding', 'identity']) || \Input::get('force-new', false) == true) $view = 'site.pages.service';
// Return view to the user
return View::make($view,[
// Namespace is also used for our body class.
// Add a space so that all pages can use the 'service' class
'namespace' => 'service ' . $service->code_name,
'service' => $service,
'nextService' => $nextService,
'breadcrumb' => $breadcrumb
]);
}
}