*/ protected $fillable = [ 'message', 'to', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'message' => 'encrypted', ]; // * RELATIONSHIPS /** * BelongsTo customer relation. */ public function toCustomer(): BelongsTo { return $this->belongsTo(Customer::class, 'to'); } /** * BelongsTo customer relation. */ public function fromCustomer(): BelongsTo { return $this->belongsTo(Customer::class, 'from'); } /** * MorphOne notification relation. */ public function notifiable(): MorphOne { return $this->morphOne(Notification::class, 'notifiable'); } // * METHODS /** * Created at nice date. */ public function createdAtNiceDate(): Attribute { return Attribute::make( get: fn () => (new NiceDate())->get(null, '', $this->created_at, []) ); } /** * Get older messages. */ public static function getMessagesOlderThan(int $days): Builder { return self::query()->where('updated_at', '<', now()->subDays($days)); } /** * Convert the model instance to an array. * ! Make sure we use correct nicedate formater */ public function toArray(): array { return array_merge(parent::toArray(), [ 'created_at' => $this->created_at, ]); } }