usamamuneerchaudhary /
commentify
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Usamamuneerchaudhary\Commentify\Models; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
||
| 6 | use Illuminate\Database\Eloquent\Model; |
||
| 7 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
||
| 8 | use Illuminate\Database\Eloquent\Relations\HasMany; |
||
| 9 | use Illuminate\Database\Eloquent\Relations\MorphTo; |
||
| 10 | use Illuminate\Database\Eloquent\SoftDeletes; |
||
| 11 | use Usamamuneerchaudhary\Commentify\Database\Factories\CommentFactory; |
||
| 12 | use Usamamuneerchaudhary\Commentify\Models\Presenters\CommentPresenter; |
||
| 13 | use Usamamuneerchaudhary\Commentify\Scopes\CommentScopes; |
||
| 14 | use Usamamuneerchaudhary\Commentify\Scopes\HasLikes; |
||
| 15 | |||
| 16 | class Comment extends Model |
||
| 17 | { |
||
| 18 | |||
| 19 | use CommentScopes, SoftDeletes, HasFactory, HasLikes; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $table = 'comments'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string[] |
||
| 28 | */ |
||
| 29 | protected $fillable = ['body']; |
||
| 30 | |||
| 31 | protected $withCount = [ |
||
| 32 | 'likes', |
||
| 33 | ]; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return CommentPresenter |
||
| 37 | */ |
||
| 38 | public function presenter(): CommentPresenter |
||
| 39 | { |
||
| 40 | return new CommentPresenter($this); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return bool |
||
| 45 | */ |
||
| 46 | public function isParent(): bool |
||
| 47 | { |
||
| 48 | return is_null($this->parent_id); |
||
|
0 ignored issues
–
show
|
|||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return BelongsTo |
||
| 53 | */ |
||
| 54 | public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
| 55 | { |
||
| 56 | return $this->belongsTo(User::class); |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @return HasMany |
||
| 61 | */ |
||
| 62 | public function children(): \Illuminate\Database\Eloquent\Relations\HasMany |
||
| 63 | { |
||
| 64 | return $this->hasMany(Comment::class, 'parent_id')->oldest(); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return MorphTo |
||
| 69 | */ |
||
| 70 | public function commentable(): \Illuminate\Database\Eloquent\Relations\MorphTo |
||
| 71 | { |
||
| 72 | return $this->morphTo(); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return CommentFactory |
||
| 77 | */ |
||
| 78 | protected static function newFactory(): CommentFactory |
||
| 79 | { |
||
| 80 | return CommentFactory::new(); |
||
| 81 | } |
||
| 82 | } |
||
| 83 |