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/PostService.php
<?php


namespace App\KommaApp\Posts;


use App\KommaApp\Posts\Models\Post;
use Carbon\Carbon;

class PostService
{

    private $today;

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

    public function getAllPosts($pagination = false, $itemsPerPage = 9)
    {

        $posts = \App::getSite()
            ->posts()
            ->with('translation', 'images')
            ->where('active', 1)
            ->where('date', '<=', $this->today)
            ->orderBy('date','desc')
            ->orderBy('created_at', 'desc');

        if($pagination)
        {
            $posts = $posts->paginate($itemsPerPage);
        }
        else
        {
            $posts = $posts->get();
        }
        return $posts;
    }

    public function getLatestPosts($amount = 5){

        return $posts = \App::getSite()
            ->posts()
            ->with('translation', 'images')
            ->where('active', 1)
            ->where('date', '<=', $this->today)
            ->orderBy('date','desc')
            ->orderBy('created_at', 'desc')
            ->take($amount)
            ->get();

    }

}