1 | <?php namespace Arcanesoft\Blog\Models\Presenters; |
||
17 | trait PostPresenter |
||
18 | { |
||
19 | /* ----------------------------------------------------------------- |
||
20 | | Accessors |
||
21 | | ----------------------------------------------------------------- |
||
22 | */ |
||
23 | |||
24 | /** |
||
25 | * Get the locale's native name. |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | public function getLocaleNativeAttribute() |
||
43 | |||
44 | /** |
||
45 | * Get the content attribute. |
||
46 | * |
||
47 | * @return \Illuminate\Support\HtmlString |
||
48 | */ |
||
49 | public function getContentAttribute() |
||
53 | |||
54 | /** |
||
55 | * Get the status attribute. |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | 2 | public function getStatusAttribute() |
|
60 | { |
||
61 | 2 | return $this->isDraft() ? PostStatus::STATUS_DRAFT : PostStatus::STATUS_PUBLISHED; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * Set the status attribute. |
||
66 | * |
||
67 | * @param string $status |
||
68 | * |
||
69 | * @return self |
||
70 | */ |
||
71 | 2 | public function setStatusAttribute($status) |
|
72 | { |
||
73 | 2 | $this->setAttribute('is_draft', $status === PostStatus::STATUS_DRAFT); |
|
74 | |||
75 | 2 | return $this; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get the status name attribute. |
||
80 | * |
||
81 | * @return string|null |
||
82 | */ |
||
83 | 2 | public function getStatusNameAttribute() |
|
84 | { |
||
85 | 2 | return PostStatus::get( |
|
86 | 2 | $this->getStatusAttribute() |
|
87 | ); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * Get the post statuses. |
||
92 | * |
||
93 | * @return \Illuminate\Support\Collection |
||
94 | */ |
||
95 | 4 | public static function getStatuses() |
|
99 | |||
100 | /* ----------------------------------------------------------------- |
||
101 | | Other Methods |
||
102 | | ----------------------------------------------------------------- |
||
103 | */ |
||
104 | |||
105 | /** |
||
106 | * Check if the post's status is "draft". |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | abstract public function isDraft(); |
||
111 | |||
112 | /* ----------------------------------------------------------------- |
||
113 | | URL Accessors |
||
114 | | ----------------------------------------------------------------- |
||
115 | */ |
||
116 | |||
117 | /** |
||
118 | * Get the show URL. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 2 | public function getShowUrl() |
|
123 | { |
||
124 | 2 | return route('admin::blog.posts.show', [$this]); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Get the edit URL. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 2 | public function getEditUrl() |
|
133 | { |
||
134 | 2 | return route('admin::blog.posts.edit', [$this]); |
|
135 | } |
||
136 | |||
137 | /* ----------------------------------------------------------------- |
||
138 | | Eloquent Methods |
||
139 | | ----------------------------------------------------------------- |
||
140 | */ |
||
141 | |||
142 | /** |
||
143 | * Get an attribute from the $attributes array. |
||
144 | * |
||
145 | * @param string $key |
||
146 | * @return mixed |
||
147 | */ |
||
148 | abstract protected function getAttributeFromArray($key); |
||
149 | |||
150 | /** |
||
151 | * Set a given attribute on the model. |
||
152 | * |
||
153 | * @param string $key |
||
154 | * @param mixed $value |
||
155 | * |
||
156 | * @return self |
||
157 | */ |
||
158 | abstract public function setAttribute($key, $value); |
||
159 | } |
||
160 |