2
2
3
3
namespace Chriscreates \Blog \Traits \Post ;
4
4
5
+ use Carbon \Carbon ;
6
+
5
7
trait PostAttributes
6
8
{
7
9
public function getTagsCountAttribute ()
@@ -11,13 +13,49 @@ public function getTagsCountAttribute()
11
13
12
14
public function isPublished ()
13
15
{
14
- return $ this ->status == self ::PUBLISHED ;
16
+ return $ this ->status == self ::PUBLISHED
17
+ && $ this ->published_at != null ;
15
18
}
16
19
17
- public function isNotPublished ()
20
+ public function isDraft ()
18
21
{
19
22
return $ this ->status == self ::DRAFT
20
- || $ this ->status == self ::SCHEDULED ;
23
+ && $ this ->published_at == null ;
24
+ }
25
+
26
+ public function isScheduled ()
27
+ {
28
+ return $ this ->status == self ::SCHEDULED
29
+ && $ this ->published_at > Carbon::now ();
30
+ }
31
+
32
+ public function isNotPublished ()
33
+ {
34
+ return $ this ->isDraft () || $ this ->isScheduled ();
35
+ }
36
+
37
+ public function scheduleFor ($ date )
38
+ {
39
+ if ( ! $ date instanceof Carbon) {
40
+ $ date = new Carbon ($ date );
41
+ }
42
+
43
+ $ this ->update ([
44
+ 'status ' => self ::SCHEDULED ,
45
+ 'published_at ' => $ date ,
46
+ ]);
47
+
48
+ return $ this ;
49
+ }
50
+
51
+ public function publish ()
52
+ {
53
+ $ this ->update ([
54
+ 'status ' => self ::PUBLISHED ,
55
+ 'published_at ' => now (),
56
+ ]);
57
+
58
+ return $ this ;
21
59
}
22
60
23
61
public function getTimeToReadAttribute ()
0 commit comments