diff --git a/app/Models/Content.php b/app/Models/Content.php index a91de453..1723966d 100644 --- a/app/Models/Content.php +++ b/app/Models/Content.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Enumerations\ContentStatuses; use App\Http\Requests\Request; +use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\App; @@ -64,6 +65,14 @@ class Content extends Model ->select('contents.*') ->with('author') ->join('modules', 'modules.handler', '=', 'contents.module_handler') + ->where(function ($query) { + $query->where('published_from', '>', Carbon::now()) + ->orWhereNull('published_from'); + }) + ->where(function ($query) { + $query->where('published_to', '<', Carbon::now()) + ->orWhereNull('published_to'); + }) ->where('language', LaravelLocalization::getCurrentLocale()) ->where('modules.enabled', true); } diff --git a/modules/Blog/ArticleList/Handlers/ArticleList.php b/modules/Blog/ArticleList/Handlers/ArticleList.php index c387d4ac..39838d4c 100644 --- a/modules/Blog/ArticleList/Handlers/ArticleList.php +++ b/modules/Blog/ArticleList/Handlers/ArticleList.php @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller; use App\Http\Requests\Request; use App\Models\Content; use App\Models\User; +use Carbon\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Input; @@ -98,6 +99,14 @@ class ArticleList extends Handler $articles = ArticleModel::where('module_handler', Article::class) ->with('comments') ->with('category') + ->where(function ($query) { + $query->where('published_from', '>', Carbon::now()) + ->orWhereNull('published_from'); + }) + ->where(function ($query) { + $query->where('published_to', '<', Carbon::now()) + ->orWhereNull('published_to'); + }) ->orderBy('published_from', 'DESC') ->orderBy('created_at', 'DESC');