1 | <?php |
||
16 | class DiscussConversation extends Model |
||
17 | { |
||
18 | use Countable, |
||
19 | Sluggable, |
||
20 | FloodGate, |
||
21 | DiscussConversationPresenter, |
||
22 | HasMentionsTrait; |
||
23 | |||
24 | /** |
||
25 | * The attributes that are mass assignable. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $fillable = [ |
||
30 | 'user_id', |
||
31 | 'category_id', |
||
32 | 'title', |
||
33 | 'slug', |
||
34 | 'post_count', |
||
35 | 'participants_count', |
||
36 | 'is_locked', |
||
37 | 'is_pinned', |
||
38 | 'is_solved', |
||
39 | 'is_edited', |
||
40 | 'edit_count' |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * The accessors to append to the model's array form. |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected $appends = [ |
||
49 | 'conversation_url', |
||
50 | 'last_page' |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * The attributes that should be mutated to dates. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $dates = [ |
||
59 | 'edited_at' |
||
60 | ]; |
||
61 | |||
62 | /** |
||
63 | * The "booting" method of the model. |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | protected static function boot() |
||
81 | |||
82 | /** |
||
83 | * Return the field to slug. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function slugStrategy(): string |
||
91 | |||
92 | /** |
||
93 | * Return the count cache configuration. |
||
94 | * |
||
95 | * @return array |
||
96 | */ |
||
97 | public function countCaches(): array |
||
104 | |||
105 | /** |
||
106 | * Get the category that owns the conversation. |
||
107 | * |
||
108 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
109 | */ |
||
110 | public function category() |
||
114 | |||
115 | /** |
||
116 | * Get the user that owns the conversation. |
||
117 | * |
||
118 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
119 | */ |
||
120 | public function user() |
||
124 | |||
125 | /** |
||
126 | * Get the posts for the conversation. |
||
127 | * |
||
128 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
129 | */ |
||
130 | public function posts() |
||
134 | |||
135 | /** |
||
136 | * Get the posts for the conversation. |
||
137 | * |
||
138 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
139 | */ |
||
140 | public function users() |
||
144 | |||
145 | /** |
||
146 | * Get the first post of the conversation. |
||
147 | * |
||
148 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
149 | */ |
||
150 | public function firstPost() |
||
154 | |||
155 | /** |
||
156 | * Get the solved post of the conversation. |
||
157 | * |
||
158 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
159 | */ |
||
160 | public function solvedPost() |
||
164 | |||
165 | /** |
||
166 | * Get the last post of the conversation. |
||
167 | * |
||
168 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
169 | */ |
||
170 | public function lastPost() |
||
174 | |||
175 | /** |
||
176 | * Get the user that edited the conversation. |
||
177 | * |
||
178 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
179 | */ |
||
180 | public function editedUser() |
||
184 | |||
185 | /** |
||
186 | * Get the discuss logs for the conversation. |
||
187 | * |
||
188 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
189 | */ |
||
190 | public function discussLogs() |
||
194 | |||
195 | /** |
||
196 | * Get the logs and posts related to the current conversation |
||
197 | * for the given the pagination posts and return the data |
||
198 | * ordered by `created_at` as a Collection. |
||
199 | * |
||
200 | * @param \Illuminate\Support\Collection $posts |
||
201 | * @param int $page |
||
202 | * |
||
203 | * @return \Illuminate\Support\Collection |
||
204 | */ |
||
205 | public function getPostsWithLogs(Collection $posts, int $page): Collection |
||
244 | |||
245 | /** |
||
246 | * Get the previous post related to the current conversation with |
||
247 | * the given date. |
||
248 | * |
||
249 | * @param string $createdAt |
||
250 | * |
||
251 | * @return \Xetaravel\Models\DiscussPost|null |
||
252 | */ |
||
253 | protected function getPreviousPost(string $createdAt) |
||
261 | } |
||
262 |