File: D:/HostingSpaces/SBogers10/base.komma.pro/app/Posts/PostController.php
<?php
namespace App\Posts;
use App\Base\Controller;
use App\Buttons\Models\Button;
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);
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$this->keepTrackOfPagination($this->postPaginationKey);
// 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');
$latestPosts = $this->postService->getLatestPost(10)->get();
$page = $this->links->posts->node;
// Make language menu for given page
$languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
$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);
// Return view
return view('templates.posts_show',[
'page' => $page,
'post' => $post,
'latestPosts' => $latestPosts,
'components' => $components,
'links' => $this->links,
'previousRoute' => $previousRoute,
'languageMenu' => $languageMenu,
]);
}
}