NiceDate::class, ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'message', 'to' ]; // * RELATIONSHIPS /** * BelongsTo customer relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function toCustomer() { return $this->belongsTo(Customers::class, 'to'); } /** * BelongsTo customer relation * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function fromCustomer() { return $this->belongsTo(Customers::class, 'from'); } /** * MorphOne notification relation * * @return \Illuminate\Database\Eloquent\Relations\MorphOne */ public function notifiable() { return $this->morphOne(Notifications::class, 'notifiable'); } // * METHODS /** * Get MessagesOlderThan attribute * * @param integer $days * @return \Illuminate\Database\Query\Builder */ public static function getMessagesOlderThan(int $days) { return Message::where('updated_at', '<', Carbon::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 ]); } }