@@ -49,6 +49,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
49
49
'declined_at ' ,
50
50
'shared_at ' ,
51
51
'sponsored_at ' ,
52
+ 'published_at ' ,
52
53
];
53
54
54
55
/**
@@ -62,6 +63,7 @@ class Article extends Model implements ReactableInterface, HasMedia, Viewable
62
63
'declined_at ' => 'datetime ' ,
63
64
'shared_at ' => 'datetime ' ,
64
65
'sponsored_at ' => 'datetime ' ,
66
+ 'published_at ' => 'datetime ' ,
65
67
'show_toc ' => 'boolean ' ,
66
68
'is_pinned ' => 'boolean ' ,
67
69
];
@@ -150,6 +152,11 @@ public function sponsoredAt(): ?Carbon
150
152
return $ this ->sponsored_at ;
151
153
}
152
154
155
+ public function publishedAt (): ?Carbon
156
+ {
157
+ return $ this ->published_at ;
158
+ }
159
+
153
160
public function isSubmitted (): bool
154
161
{
155
162
return ! $ this ->isNotSubmitted ();
@@ -249,7 +256,8 @@ public function scopeAwaitingApproval(Builder $query): Builder
249
256
250
257
public function scopePublished (Builder $ query ): Builder
251
258
{
252
- return $ query ->submitted ()
259
+ return $ query ->whereDate ('published_at ' , '<= ' , now ())
260
+ ->submitted ()
253
261
->approved ();
254
262
}
255
263
@@ -258,6 +266,7 @@ public function scopeNotPublished(Builder $query): Builder
258
266
return $ query ->where (function ($ query ) {
259
267
$ query ->whereNull ('submitted_at ' )
260
268
->orWhereNull ('approved_at ' )
269
+ ->orWhereNull ('published_at ' )
261
270
->orWhereNotNull ('declined_at ' );
262
271
});
263
272
}
@@ -300,14 +309,14 @@ public function scopeNotDeclined(Builder $query): Builder
300
309
public function scopeRecent (Builder $ query ): Builder
301
310
{
302
311
return $ query ->orderBy ('is_pinned ' , 'desc ' )
303
- ->orderBy ('submitted_at ' , 'desc ' );
312
+ ->orderBy ('published_at ' , 'desc ' );
304
313
}
305
314
306
315
public function scopePopular (Builder $ query ): Builder
307
316
{
308
317
return $ query ->withCount ('reactions ' )
309
318
->orderBy ('reactions_count ' , 'desc ' )
310
- ->orderBy ('submitted_at ' , 'desc ' );
319
+ ->orderBy ('published_at ' , 'desc ' );
311
320
}
312
321
313
322
public function scopeTrending (Builder $ query ): Builder
@@ -316,7 +325,7 @@ public function scopeTrending(Builder $query): Builder
316
325
$ query ->where ('created_at ' , '>= ' , now ()->subWeek ());
317
326
}])
318
327
->orderBy ('reactions_count ' , 'desc ' )
319
- ->orderBy ('submitted_at ' , 'desc ' );
328
+ ->orderBy ('published_at ' , 'desc ' );
320
329
}
321
330
322
331
public function markAsShared ()
@@ -328,15 +337,15 @@ public static function nextForSharing(): ?self
328
337
{
329
338
return self ::notShared ()
330
339
->published ()
331
- ->orderBy ('submitted_at ' , 'asc ' )
340
+ ->orderBy ('published_at ' , 'asc ' )
332
341
->first ();
333
342
}
334
343
335
344
public static function nexForSharingToTelegram (): ?self
336
345
{
337
346
return self ::published ()
338
347
->whereNull ('tweet_id ' )
339
- ->orderBy ('submitted_at ' , 'asc ' )
348
+ ->orderBy ('published_at ' , 'asc ' )
340
349
->first ();
341
350
}
342
351
0 commit comments