@@ -35,6 +35,7 @@ final class Article extends Model
3535 'is_pinned ' ,
3636 'submitted_at ' ,
3737 'approved_at ' ,
38+ 'shared_at ' ,
3839 ];
3940
4041 /**
@@ -43,6 +44,7 @@ final class Article extends Model
4344 protected $ dates = [
4445 'submitted_at ' ,
4546 'approved_at ' ,
47+ 'shared_at ' ,
4648 ];
4749
4850 public function id (): int
@@ -82,7 +84,7 @@ public function series()
8284
8385 public function updateSeries (Series $ series = null ): self
8486 {
85- if (is_null ( $ series) ) {
87+ if (null === $ series ) {
8688 return $ this ->removeSeries ();
8789 }
8890
@@ -122,7 +124,7 @@ public function isSubmitted(): bool
122124
123125 public function isNotSubmitted (): bool
124126 {
125- return is_null ( $ this ->submitted_at ) ;
127+ return null === $ this ->submitted_at ;
126128 }
127129
128130 public function isApproved (): bool
@@ -132,7 +134,7 @@ public function isApproved(): bool
132134
133135 public function isNotApproved (): bool
134136 {
135- return is_null ( $ this ->approved_at ) ;
137+ return null === $ this ->approved_at ;
136138 }
137139
138140 public function isPublished (): bool
@@ -150,6 +152,16 @@ public function isPinned(): bool
150152 return (bool ) $ this ->is_pinned ;
151153 }
152154
155+ public function isNotShared (): bool
156+ {
157+ return null === $ this ->shared_at ;
158+ }
159+
160+ public function isShared (): bool
161+ {
162+ return ! $ this ->isNotShared ();
163+ }
164+
153165 public function isAwaitingApproval (): bool
154166 {
155167 return $ this ->isSubmitted () && $ this ->isNotApproved ();
@@ -202,6 +214,16 @@ public function scopeNotPublished(Builder $query): Builder
202214 });
203215 }
204216
217+ public function scopeShared (Builder $ query ): Builder
218+ {
219+ return $ query ->whereNotNull ('shared_at ' );
220+ }
221+
222+ public function scopeNotShared (Builder $ query ): Builder
223+ {
224+ return $ query ->whereNull ('shared_at ' );
225+ }
226+
205227 public function scopeForTag (Builder $ query , string $ tag ): Builder
206228 {
207229 return $ query ->whereHas ('tagsRelation ' , function ($ query ) use ($ tag ) {
@@ -270,4 +292,19 @@ public function splitBody($value)
270292 {
271293 return $ this ->split ($ value );
272294 }
295+
296+ public function markAsShared ()
297+ {
298+ $ this ->update ([
299+ 'shared_at ' => now (),
300+ ]);
301+ }
302+
303+ public static function nextForSharing (): ?self
304+ {
305+ return self ::notShared ()
306+ ->published ()
307+ ->orderBy ('submitted_at ' , 'asc ' )
308+ ->first ();
309+ }
273310}
0 commit comments