File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/KommaApp/NewsArticles/NewsArticleService.php
<?php
namespace App\KommaApp\NewsArticles;
use App\KommaApp\Base\Service;
use App\KommaApp\NewsArticles\Models\NewsArticle;
use Carbon\Carbon;
class NewsArticleService extends Service
{
const ARTICLES_PER_PAGE = 10;
private $today;
public function __construct()
{
$this->today = Carbon::now()->addHour();
$this->today = $this->today->format('Y-m-d H:i:s');
parent::__construct();
}
public function getArticles(bool $pagination = true, array $excludeIds = null, int $amount = null)
{
$articles = $this->site
->newsArticles()
->with(['translation', 'images'])
->where('active', 1)
->where('date', '<=', $this->today)
->orderBy('date','desc')
->orderBy('created_at', 'desc');
if($excludeIds) $articles = $articles->whereNotIn('id', $excludeIds);
// Get the events paginated or by get with optional a given amount
if($pagination){
$articles = $articles->paginate(self::ARTICLES_PER_PAGE);
}
else {
if($amount) $articles = $articles->take($amount);
$articles = $articles->get();
}
return $articles;
}
}