@@ -49,6 +49,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
4949 'declined_at ' ,
5050 'shared_at ' ,
5151 'sponsored_at ' ,
52+ 'published_at ' ,
5253 ];
5354
5455 /**
@@ -62,6 +63,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
6263 'declined_at ' => 'datetime ' ,
6364 'shared_at ' => 'datetime ' ,
6465 'sponsored_at ' => 'datetime ' ,
66+ 'published_at ' => 'datetime ' ,
6567 'show_toc ' => 'boolean ' ,
6668 'is_pinned ' => 'boolean ' ,
6769 ];
@@ -150,6 +152,11 @@ public function sponsoredAt(): ?Carbon
150152 return $ this ->sponsored_at ;
151153 }
152154
155+ public function publishedAt (): ?Carbon
156+ {
157+ return $ this ->published_at ;
158+ }
159+
153160 public function isSubmitted (): bool
154161 {
155162 return ! $ this ->isNotSubmitted ();
@@ -192,12 +199,12 @@ public function isNotDeclined(): bool
192199
193200 public function isPublished (): bool
194201 {
195- return ! $ this ->isNotPublished ();
202+ return ! $ this ->isNotPublished () && ( $ this -> publishedAt () && $ this -> publishedAt ()-> lessThanOrEqualTo ( now ())) ;
196203 }
197204
198205 public function isNotPublished (): bool
199206 {
200- return $ this ->isNotSubmitted () || $ this ->isNotApproved ();
207+ return ( $ this ->isNotSubmitted () || $ this ->isNotApproved ()) && $ this -> published_at === null ;
201208 }
202209
203210 public function isPinned (): bool
@@ -249,7 +256,8 @@ public function scopeAwaitingApproval(Builder $query): Builder
249256
250257 public function scopePublished (Builder $ query ): Builder
251258 {
252- return $ query ->submitted ()
259+ return $ query ->whereDate ('published_at ' , '<= ' , now ())
260+ ->submitted ()
253261 ->approved ();
254262 }
255263
@@ -258,6 +266,7 @@ public function scopeNotPublished(Builder $query): Builder
258266 return $ query ->where (function ($ query ) {
259267 $ query ->whereNull ('submitted_at ' )
260268 ->orWhereNull ('approved_at ' )
269+ ->orWhereNull ('published_at ' )
261270 ->orWhereNotNull ('declined_at ' );
262271 });
263272 }
@@ -300,14 +309,14 @@ public function scopeNotDeclined(Builder $query): Builder
300309 public function scopeRecent (Builder $ query ): Builder
301310 {
302311 return $ query ->orderBy ('is_pinned ' , 'desc ' )
303- ->orderBy ('submitted_at ' , 'desc ' );
312+ ->orderBy ('published_at ' , 'desc ' );
304313 }
305314
306315 public function scopePopular (Builder $ query ): Builder
307316 {
308317 return $ query ->withCount ('reactions ' )
309318 ->orderBy ('reactions_count ' , 'desc ' )
310- ->orderBy ('submitted_at ' , 'desc ' );
319+ ->orderBy ('published_at ' , 'desc ' );
311320 }
312321
313322 public function scopeTrending (Builder $ query ): Builder
@@ -316,7 +325,7 @@ public function scopeTrending(Builder $query): Builder
316325 $ query ->where ('created_at ' , '>= ' , now ()->subWeek ());
317326 }])
318327 ->orderBy ('reactions_count ' , 'desc ' )
319- ->orderBy ('submitted_at ' , 'desc ' );
328+ ->orderBy ('published_at ' , 'desc ' );
320329 }
321330
322331 public function markAsShared ()
@@ -328,15 +337,15 @@ public static function nextForSharing(): ?self
328337 {
329338 return self ::notShared ()
330339 ->published ()
331- ->orderBy ('submitted_at ' , 'asc ' )
340+ ->orderBy ('published_at ' , 'asc ' )
332341 ->first ();
333342 }
334343
335344 public static function nexForSharingToTelegram (): ?self
336345 {
337346 return self ::published ()
338347 ->whereNull ('tweet_id ' )
339- ->orderBy ('submitted_at ' , 'asc ' )
348+ ->orderBy ('published_at ' , 'asc ' )
340349 ->first ();
341350 }
342351
0 commit comments