1 | <?php |
||
16 | class DiscussThread extends Model |
||
17 | { |
||
18 | use Countable, |
||
19 | Sluggable, |
||
20 | FloodGate, |
||
21 | DiscussThreadPresenter, |
||
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 | 'content', |
||
35 | 'comment_count', |
||
36 | 'is_locked', |
||
37 | 'is_pinned', |
||
38 | 'is_solved', |
||
39 | 'is_edited' |
||
40 | ]; |
||
41 | |||
42 | /** |
||
43 | * The accessors to append to the model's array form. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $appends = [ |
||
48 | 'thread_url', |
||
49 | 'last_page' |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * The attributes that should be mutated to dates. |
||
54 | * |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $dates = [ |
||
58 | 'edited_at' |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * The "booting" method of the model. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | protected static function boot() |
||
80 | |||
81 | /** |
||
82 | * Return the field to slug. |
||
83 | * |
||
84 | * @return string |
||
85 | */ |
||
86 | public function slugStrategy(): string |
||
90 | |||
91 | /** |
||
92 | * Return the count cache configuration. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function countCaches(): array |
||
103 | |||
104 | /** |
||
105 | * Get the category that owns the thread. |
||
106 | * |
||
107 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
108 | */ |
||
109 | public function category() |
||
113 | |||
114 | /** |
||
115 | * Get the user that owns the thread. |
||
116 | * |
||
117 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
118 | */ |
||
119 | public function user() |
||
123 | |||
124 | /** |
||
125 | * Get the comments for the thread. |
||
126 | * |
||
127 | * @return \Illuminate\Database\Eloquent\Relations\HasMany |
||
128 | */ |
||
129 | public function comments() |
||
133 | |||
134 | /** |
||
135 | * Get the solved comment of the thread. |
||
136 | * |
||
137 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
138 | */ |
||
139 | public function solvedComment() |
||
143 | |||
144 | /** |
||
145 | * Get the last comment of the thread. |
||
146 | * |
||
147 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
148 | */ |
||
149 | public function lastComment() |
||
153 | |||
154 | /** |
||
155 | * Get the user that edited the thread. |
||
156 | * |
||
157 | * @return \Illuminate\Database\Eloquent\Relations\HasOne |
||
158 | */ |
||
159 | public function editedUser() |
||
163 | |||
164 | /** |
||
165 | * Get the discuss logs for the thread. |
||
166 | * |
||
167 | * @return \Illuminate\Database\Eloquent\Relations\MorphMany |
||
168 | */ |
||
169 | public function discussLogs() |
||
173 | |||
174 | /** |
||
175 | * Get the logs and comments related to the current thread |
||
176 | * for the given the pagination comments and return the data |
||
177 | * ordered by `created_at` as a Collection. |
||
178 | * |
||
179 | * @param \Illuminate\Support\Collection $comments |
||
180 | * @param int $page |
||
181 | * |
||
182 | * @return \Illuminate\Support\Collection |
||
183 | */ |
||
184 | public function getCommentWithLogs(Collection $comments, int $page): Collection |
||
219 | |||
220 | /** |
||
221 | * Get the previous comment related to the current thread with |
||
222 | * the given date. |
||
223 | * |
||
224 | * @param string $createdAt |
||
225 | * |
||
226 | * @return \Xetaravel\Models\DiscussComment|null |
||
227 | */ |
||
228 | protected function getPreviousComment(string $createdAt) |
||
235 | } |
||
236 |