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/centrum8a/centrum8a.com/app/KommaApp/Posts/PostController.php
<?php

namespace App\KommaApp\Posts;

use App\Http\Controllers\Controller;
use App\KommaApp\Posts\Models\Post;

class PostController extends Controller
{
    private $pagePrefix = 'pages.posts.';
    private $postService;

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

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function index()
    {
        $page = $this->pageService->getPageByCodeName('posts');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);

        $posts = $this->postService->getAllPosts(true);
        $posts->withPath('/' . $this->links->posts->route);

        // Return view
        return \View::make($this->baseViewPath.$this->pagePrefix.'index',[
            'page' => $page,
            'links' => $this->links,
            'otherLanguages' => $otherLanguageRoutes,
            'posts' => $posts,
        ]);
    }

    /**
     * @return \Illuminate\Contracts\View\View
     */
    public function filters()
    {
        $filters = request('filters');
        dd('customize filter function in PostController');

//        if (sizeof($filters) != 1) {
//            throw abort(404);
//        }
//        $categoryName = $filters[0];
//
//        // Check if category exist else trow 404
//        if ( ! $category = PostCategoryTranslation::where('slug', $categoryName)
//            ->with('translatable')
//            ->first()) {
//            throw abort(404);
//        }
//
//        $page = $this->pageService->getPageByCodeName('blog');
//        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page);
//
//        //Get posts through the category
//        $posts = $category->translatable->posts()->paginate(8);
//        $posts->withPath('/' . $this->links->blog->route . '/' . $category->slug);
//
//
//        // Return view
//        return \View::make($this->baseViewPath.$this->pagePrefix.'index',[
//            'page' => $page,
//            'links' => $this->links,
//            'otherLanguages' => $otherLanguageRoutes,
//            'posts' => $posts,
//        ]);
    }

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

        // This checks if the post belongs to the set site
        if(! $post->sites->contains(\App::getSite())) throw abort(404);

        $page = $this->pageService->getPageByCodeName('posts');
        $otherLanguageRoutes = $this->languageService->getOtherLanguagesRoutes($page, $post);

        // Get the latest posts
        $posts = $this->postService->getLatestPosts();

        // Decode the dynamic content
        $post->translation = $this->decodeDynamicContent( $post->translation );

        // Return view
        return \View::make($this->baseViewPath.$this->pagePrefix.'show',[
            'page' => $page,
            'post' => $post,
            'links' => $this->links,
            'posts' => $posts,
            'otherLanguages' => $otherLanguageRoutes
        ]);
    }

}