File: D:/HostingSpaces/SBogers110/franciscaansebeweging.nl/app/Komma/Posts/PostController.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Posts;
use Carbon\Carbon;
use Komma\Blocks\BlockService;
use Komma\Categories\Models\Category;
use Komma\LanguageService;
use Komma\Pages\PageService;
class PostController extends \BaseController
{
public $data;
protected $pageService;
protected $blockService;
protected $postService;
public function __construct(PageService $pageService, BlockService $blockService, PostService $postService)
{
parent::__construct();
$this->pageService = $pageService;
$this->blockService = $blockService;
$this->postService = $postService;
}
//Overview page
public function index($page = null){
if($page == null){
$page = $this->pageService->getPageByCodeName('blog');
}
// $posts = $this->postService->getAllPosts();
$links = $this->pageService->getAllRoutes();
return \View::make('layouts.pages.posts.index')
->with('page', $page)
->with('links', $links);
}
public function category($id){
$page = $this->pageService->getPageByCodeName('blog');
$category = Category::with(['translation', 'images'])->find($id);
$links = $this->pageService->getAllRoutes();
// Overrule Blog pages
$page->category = $category;
$page->translation->name = $category->translation->name;
$page->translation->meta_title = $category->translation->name .' | '.$page->translation->meta_title;
$page->translation->description = $category->translation->description;
$page->translation->button = trans('translations.showArticles');
$page->images = $category->images;
// Reload posts by front-end model of post...
$posts = [];
foreach ($category->posts as $post) $posts[] = $post->id;
$posts = $this->postService->getAllPosts(true, 6, $posts);
$this->postService->makeCarbonDate($posts);
return \View::make('layouts.pages.posts.category')
->with('page', $page)
->with('posts', $posts)
->with('links', $links);
}
public function show($postId){
$page = $this->pageService->getPageByCodeName('blog');
//Load post content and translation of this post
$post = $this->postService->getPost($postId);
$links = $this->pageService->getAllRoutes();
$category = $post->category->translations->first();
$category->route = $category->routes->first()->route;
$post->date = Carbon::createFromFormat('Y-m-d H:i:s', $post->date);
return \View::make('layouts.pages.posts.show')
->with('page', $page)
->with('post', $post)
->with('category', $category)
->with('links', $links);
}
}