File: D:/HostingSpaces/SBogers93/fitale.nl/app/Komma/Pages/PageService.php
<?php
namespace Komma\Pages;
use Carbon\Carbon;
use Komma\Blocks\Models\Block;
use Komma\Pages\Models\Page;
class PageService {
protected $pageRepository;
public function __construct(PageRepository $pageRepository)
{
$this->pageRepository = $pageRepository;
}
public function getPageContent($id){
if(!$page = Page::where('id','=',$id)
->with('translation')
->with('blocks.translation')
->with('images')
->first()) \App::abort(404, 'Page not found');
$page->blocks = Block::where('active', '=', 1)
->with('translation')
->with('images')
->get();
$page->blocks = $page->blocks->keyBy('code_name');
return $page;
}
public function getUrl($code_name = null){
$links = $this->pageRepository->getUrl($code_name);
$linksArray = [];
foreach ($links as $link){
$route = $link->route;
if($link->code_name == 'home') $route = '';
$linksArray[$link->code_name] = (object)['route' => $route, 'name' => $link->name];
}
return (object)$linksArray;
}
public function getPageByCodeName($codeName){
if(!$page = Page::where('code_name','=', $codeName)
->with('blocks.translation')
->with('translation')
->first()) \App::abort(404, 'Page not found');
return $page;
}
}