@@ -37,6 +37,7 @@ final class Article extends Model
3737 'is_pinned ' ,
3838 'submitted_at ' ,
3939 'approved_at ' ,
40+ 'shared_at ' ,
4041 ];
4142
4243 /**
@@ -45,6 +46,7 @@ final class Article extends Model
4546 protected $ dates = [
4647 'submitted_at ' ,
4748 'approved_at ' ,
49+ 'shared_at ' ,
4850 ];
4951
5052 public function id (): int
@@ -84,7 +86,7 @@ public function series()
8486
8587 public function updateSeries (Series $ series = null ): self
8688 {
87- if (is_null ( $ series) ) {
89+ if (null === $ series ) {
8890 return $ this ->removeSeries ();
8991 }
9092
@@ -124,7 +126,7 @@ public function isSubmitted(): bool
124126
125127 public function isNotSubmitted (): bool
126128 {
127- return is_null ( $ this ->submitted_at ) ;
129+ return null === $ this ->submitted_at ;
128130 }
129131
130132 public function isApproved (): bool
@@ -134,7 +136,7 @@ public function isApproved(): bool
134136
135137 public function isNotApproved (): bool
136138 {
137- return is_null ( $ this ->approved_at ) ;
139+ return null === $ this ->approved_at ;
138140 }
139141
140142 public function isPublished (): bool
@@ -152,6 +154,16 @@ public function isPinned(): bool
152154 return (bool ) $ this ->is_pinned ;
153155 }
154156
157+ public function isNotShared (): bool
158+ {
159+ return null === $ this ->shared_at ;
160+ }
161+
162+ public function isShared (): bool
163+ {
164+ return ! $ this ->isNotShared ();
165+ }
166+
155167 public function isAwaitingApproval (): bool
156168 {
157169 return $ this ->isSubmitted () && $ this ->isNotApproved ();
@@ -204,6 +216,16 @@ public function scopeNotPublished(Builder $query): Builder
204216 });
205217 }
206218
219+ public function scopeShared (Builder $ query ): Builder
220+ {
221+ return $ query ->whereNotNull ('shared_at ' );
222+ }
223+
224+ public function scopeNotShared (Builder $ query ): Builder
225+ {
226+ return $ query ->whereNull ('shared_at ' );
227+ }
228+
207229 public function scopeForTag (Builder $ query , string $ tag ): Builder
208230 {
209231 return $ query ->whereHas ('tagsRelation ' , function ($ query ) use ($ tag ) {
@@ -272,4 +294,19 @@ public function splitBody($value)
272294 {
273295 return $ this ->split ($ value );
274296 }
297+
298+ public function markAsShared ()
299+ {
300+ $ this ->update ([
301+ 'shared_at ' => now (),
302+ ]);
303+ }
304+
305+ public static function nextForSharing (): ?self
306+ {
307+ return self ::notShared ()
308+ ->published ()
309+ ->orderBy ('submitted_at ' , 'asc ' )
310+ ->first ();
311+ }
275312}
0 commit comments