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/zelfverkopen.komma.pro/app/KommaApp/Posts/PostComposer.php
<?php


namespace App\KommaApp\Posts;

use App\KommaApp\PostCategories\Models\PostCategory;
use Carbon\Carbon;
use Illuminate\View\View;

class PostComposer
{

    static $posts;
    private $today;

    public function __construct()
    {
        $this->today = Carbon::now()->addHour();
        $this->today = $this->today->format('Y-m-d H:i:s');
    }

    /**
     * Bind data to the view.
     *
     * @param  View $view
     * @return void
     */
    public function message(View $view)
    {

        // Only load posts once
        if (!static::$posts) {

            if(!empty(\App::getSite())) {

                $coranaCategory = PostCategory::where('id', 10)
                    ->where('active', 1)
                    ->first();

                static::$posts = $coranaCategory->posts()
                    ->with('translation', 'images', 'author', 'author.images', 'post_categories',
                        'post_categories.translation')
                    ->where('active', 1)
                    ->where('date', '<=', $this->today)
                    ->orderBy('date', 'desc')
                    ->take(4)
                    ->get();
            }
        }

        if(empty(\App::getSite())) {
            $view->with('posts', collect());
            return;
        }

        $view->with('posts', static::$posts);

    }

}