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/SBogers10/inzigd.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\Pages\Models\Page;
use App\Komma\Posts\Models\Post;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;

final class PostController extends Controller
{
    private $postService;
    private $postPaginationKey = 'postPagination';

    public function __construct(PostService $postService)
    {
        parent::__construct();
        $this->postService = $postService;
    }

    /**
     *
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {

        // Get the page through the set links
        $page = $this->links->posts->node;

        $posts = $this->postService->getPostsPaginated();
        $posts->withPath($this->links->posts->route);

        $this->keepTrackOfPagination($this->postPaginationKey);

        // If we are on the first page return a custom view
        if($posts->currentPage() == 1) return $this->indexFirstPage($page, $posts);

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

    /**
     * The first page of the index
     *
     * @param  Page  $page
     * @param  LengthAwarePaginator $posts
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    private function indexFirstPage(Page $page, LengthAwarePaginator $posts)
    {

        // Divide posts items into 2 groups
        $postItems = $posts->items();
        $highlightedPosts = array_splice($postItems,0 ,4);

        // Return view
        return view('site.templates.posts_index_first',[
            'page' => $page,
            'links' => $this->links,
            'highlightedPost' => array_shift($highlightedPosts),
            'subHighlightedPosts' => $highlightedPosts,
            'postItems' => $postItems,
            'postPaginator' => $posts,
        ]);
    }

    /**
     * @param Post $post
     * @return \Illuminate\Contracts\View\View
     */
    public function show(Post $post)
    {

        // Load the needed relations
        $post->load('translation','translations', 'sites', 'images');

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

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


}