classDatabaseNotificationextendsModel { protected$connection = 'B資料庫'; /** * The "type" of the primary key ID. * * @var string */ protected$keyType = 'string';
/** * Indicates if the IDs are auto-incrementing. * * @var bool */ public$incrementing = false;
/** * The table associated with the model. * * @var string */ protected$table = 'notifications';
/** * The guarded attributes on the model. * * @var array */ protected$guarded = [];
/** * The attributes that should be cast to native types. * * @var array */ protected$casts = [ 'data' => 'array', 'read_at' => 'datetime', ];
/** * Get the notifiable entity that the notification belongs to. * * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ publicfunctionnotifiable() { return$this->morphTo(); }
/** * Mark the notification as read. * * @return void */ publicfunctionmarkAsRead() { if (is_null($this->read_at)) { $this->forceFill(['read_at' => $this->freshTimestamp()])->save(); } }
/** * Mark the notification as unread. * * @return void */ publicfunctionmarkAsUnread() { if (! is_null($this->read_at)) { $this->forceFill(['read_at' => null])->save(); } }
/** * Determine if a notification has been read. * * @return bool */ publicfunctionread() { return$this->read_at !== null; }
/** * Determine if a notification has not been read. * * @return bool */ publicfunctionunread() { return$this->read_at === null; }