- if (empty($commentId)) {
- $query->whereRaw('page_id = ? AND parent_id IS NULL', [$pageId]);
- } else {
- $query->whereRaw('page_id = ? AND parent_id = ?', [$pageId, $commentId]);
+ public function getCommentById($commentId) {
+ return self::where('id', '=', $commentId)->with(['createdBy' => function($query) {
+ $query->select('id', 'name', 'image_id');
+ }, 'updatedBy' => function($query) {
+ $query->select('id', 'name');
+ }, 'createdBy.avatar' => function ($query) {
+ $query->select('id', 'path', 'url');
+ }])->first();
+ }
+
+ public function getCreatedAttribute() {
+ $created = [
+ 'day_time_str' => $this->created_at->toDayDateTimeString(),
+ 'diff' => $this->created_at->diffForHumans()
+ ];
+ return $created;
+ }
+
+ public function getUpdatedAttribute() {
+ if (empty($this->updated_at)) {
+ return null;