HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/Neopoints/momsecurity.be/app/Posts/PostController.php
<?php

namespace App\Posts;

use App\Base\Controller;
use App\Buttons\Models\Button;
use App\PostLabels\Models\PostLabel;
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);

        $categories = PostLabel::with('translation')->has('translation')->get();

        // Return view
        return view('templates.posts_index',[
            'page' => $page,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
            'posts' => $posts,
            'categories' => $categories,
        ]);
    }

    /**
     * @param Post $post
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Post $post)
    {
        $post->load('translation','translations');

        $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);

        $nextPosts = $this->postService->getNextPosts($post);

        // Return view
        return view('templates.posts_show',[
            'page' => $page,
            'post' => $post,
            'components' => $components,
            'links' => $this->links,
            'previousRoute' => $previousRoute,
            'languageMenu' => $languageMenu,
            'nextPosts' => $nextPosts,
        ]);
    }

    public function category(PostLabel $postLabel)
    {

        $postLabel->load('translation');

        $page = $this->links->posts->node;

        $posts = $this->postService->getPostsByCategoryPaginated($postLabel);
        $posts->withPath($this->links->posts->route . '/' . $postLabel->translation->slug);

        // Make language menu for given page
        $languageMenu = $this->pageService->makeLanguageSwitchForPage($this->links->{$page->code_name}, $this->links->home);
        $this->keepTrackOfPagination($this->postPaginationKey);

        $categories = PostLabel::with('translation')->has('translation')->get();

        // Return view
        return view('templates.posts_index',[
            'page' => $page,
            'links' => $this->links,
            'languageMenu' => $languageMenu,
            'posts' => $posts,
            'categories' => $categories,
            'activePostLabel' => $postLabel
        ]);

    }

    public function latest()
    {
        return PostResource::collection($this->postService->getLatestPost(4));
    }

}