*/ protected $fillable = [ 'message', 'to' ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'message' => 'encrypted' ]; // * RELATIONSHIPS /** * BelongsTo customer relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function toCustomer() { return $this->belongsTo(Customer::class, 'to'); } /** * BelongsTo customer relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function fromCustomer() { return $this->belongsTo(Customer::class, 'from'); } /** * MorphOne notification relation * * @return \Illuminate\Database\Eloquent\Relations\MorphOne */ public function notifiable(): MorphOne { return $this->morphOne(Notifications::class, 'notifiable'); } // * METHODS /** * created_at_nice_date attribute * * @return \Illuminate\Database\Eloquent\Casts\Attribute */ public function createdAtNiceDate(): Attribute { return Attribute::make( get: fn () => (new NiceDate())->get(null, '', $this->created_at, []) ); } /** * Get MessagesOlderThan attribute * * @param integer $days * @return \Illuminate\Contracts\Database\Eloquent\Builder */ 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 * * @return array */ public function toArray() { return array_merge(parent::toArray(), [ 'created_at' => $this->created_at ]); } }