File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/Posts/PostController.php
<?php
namespace App\Komma\Posts;
use App\Komma\Base\Controller;
use App\Komma\Components\ComponentService;
use App\Komma\Posts\Models\Post;
class PostController extends Controller
{
/** @var PostService */
private $postService;
/** @var string */
private $postPaginationKey = 'postPagination';
public function __construct()
{
parent::__construct();
$this->postService = app()->make(PostService::class);
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
// Get the post through the set links
$page = $this->links->posts->node;
$posts = $this->postService->getPostsPaginated();
$posts->withPath($this->links->posts->route);
$this->keepTrackOfPagination($this->postPaginationKey);
// Make language menu for index page
// $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->posts, $this->links->home);
// Return view
return view('site.templates.posts_index', [
'page' => $page,
'links' => $this->links,
'posts' => $posts,
// 'languageMenu' => $languageMenu,
]);
}
/**
* @param Post $post
* @return \Illuminate\Contracts\View\View
*/
public function show(Post $post)
{
$post->load('translation', 'images');
if (! $post->active) {
abort(404);
}
// Get the page through the set links
$page = $this->links->posts->node;
$componentService = app(ComponentService::class);
$components = $componentService->getViewComponents($post->translation);
// Create previous route for better navigation UX
$previousRoute = $this->createPreviousRoute($this->postPaginationKey, $this->links->posts->route);
$otherPosts = $this->postService->getNextPosts($post);
// Make language menu for found index page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->posts);
// $this->pageService->extendLanguageMenuWithResource($languageMenu, $post, $this->links->home);
// Return view
return view('site.templates.posts_show', [
'page' => $page,
'post' => $post,
'otherModels' => $otherPosts,
'components' => $components,
'links' => $this->links,
'previousRoute' => $previousRoute,
'languageMenu' => $languageMenu,
]);
}
}