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