XetaIO /
Xetaravel
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Xetaravel\Models; |
||
| 6 | |||
| 7 | use Eloquence\Behaviours\CountCache\CountedBy; |
||
| 8 | use Eloquence\Behaviours\CountCache\HasCounts; |
||
| 9 | use Illuminate\Database\Eloquent\Attributes\ObservedBy; |
||
| 10 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
||
| 11 | use Illuminate\Database\Eloquent\Relations\HasOne; |
||
| 12 | use Xetaio\Mentions\Models\Traits\HasMentionsTrait; |
||
| 13 | use Xetaravel\Models\Gates\FloodGate; |
||
| 14 | use Xetaravel\Models\Presenters\DiscussPostPresenter; |
||
| 15 | use Xetaravel\Observers\DiscussPostObserver; |
||
| 16 | |||
| 17 | #[ObservedBy([DiscussPostObserver::class])] |
||
| 18 | class DiscussPost extends Model |
||
| 19 | { |
||
| 20 | use DiscussPostPresenter; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 21 | use FloodGate; |
||
| 22 | use HasCounts; |
||
| 23 | use HasMentionsTrait; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The attributes that are mass assignable. |
||
| 27 | * |
||
| 28 | * @var array |
||
| 29 | */ |
||
| 30 | protected $fillable = [ |
||
| 31 | 'user_id', |
||
| 32 | 'conversation_id', |
||
| 33 | 'content', |
||
| 34 | 'is_solved', |
||
| 35 | 'is_edited' |
||
| 36 | ]; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * The accessors to append to the model's array form. |
||
| 40 | * |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $appends = [ |
||
| 44 | 'content_markdown', |
||
| 45 | 'post_url' |
||
| 46 | ]; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The attributes that should be cast. |
||
| 50 | */ |
||
| 51 | protected function casts(): array |
||
| 52 | { |
||
| 53 | return [ |
||
| 54 | 'is_edited' => 'boolean' |
||
| 55 | ]; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Get the user that owns the post. |
||
| 60 | * |
||
| 61 | * @return BelongsTo |
||
| 62 | */ |
||
| 63 | #[CountedBy(as: 'discuss_post_count')] |
||
| 64 | public function user(): BelongsTo |
||
| 65 | { |
||
| 66 | return $this->belongsTo(User::class)->withTrashed(); |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Get the conversation that owns the post. |
||
| 71 | * |
||
| 72 | * @return BelongsTo |
||
| 73 | */ |
||
| 74 | #[CountedBy(as: 'post_count')] |
||
| 75 | public function conversation(): BelongsTo |
||
| 76 | { |
||
| 77 | return $this->belongsTo(DiscussConversation::class); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Get the user that edited the post. |
||
| 82 | * |
||
| 83 | * @return HasOne |
||
| 84 | */ |
||
| 85 | public function editedUser(): HasOne |
||
| 86 | { |
||
| 87 | return $this->hasOne(User::class, 'id', 'edited_user_id')->withTrashed(); |
||
| 88 | } |
||
| 89 | } |
||
| 90 |