File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Posts/PostController.php
<?php
namespace App\Posts;
use App\Base\Controller;
use App\Posts\Models\Post;
use Komma\KMS\Components\ComponentService;
final class PostController extends Controller
{
private $postService;
private $postPaginationKey = 'postPagination';
public function __construct(PostService $postService)
{
parent::__construct();
$this->postService = $postService;
}
/**
* @return \Illuminate\Contracts\View\View
*/
public function index()
{
$page = $this->links->posts->node;
$posts = $this->postService->getPostsPaginated();
$posts->withPath($this->links->posts->route);
$this->keepTrackOfPagination($this->postPaginationKey);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
// Return view
return view('templates.posts_index',[
'page' => $page,
'links' => $this->links,
'languageMenu' => $languageMenu,
'posts' => $posts,
]);
}
/**
* @param Post $post
* @return \Illuminate\Contracts\View\View
*/
public function show(Post $post)
{
$post->load('translation','translations', 'sites');
$componentService = app(ComponentService::class);
$components = !app()->runningInConsole() ? $componentService->getViewComponents($post->translation) : collect();
// Create previous route for better navigation UX
$previousRoute = $this->createPreviousRoute($this->postPaginationKey, $this->links->posts->route);
// Make language menu for given page
$page = $this->links->posts->node;
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->posts, $this->links->home);
// Return view
return view('templates.posts_show',[
'page' => $page,
'components' => $components,
'post' => $post,
'links' => $this->links,
'languageMenu' => $languageMenu,
'previousRoute' => $previousRoute,
]);
}
}