getAttr<R> method

R getAttr<R>(
  1. String key
)
inherited

Typed attribute read with casts and accessors applied.

Implementation

R getAttr<R>(String key) {
  final accessor = modelDefinition.accessors[key];
  if (accessor != null) {
    return accessor(this) as R;
  }
  final raw = _attributes[key];
  final cast = modelDefinition.casts[key];
  final value = cast == null ? raw : cast.get(raw);
  // Laravel's getDates and `datetime` casts give a Carbon; only an uncast
  // column keeps the driver's text.
  return (value is DatabaseDateTime && (cast != null || _isTimestamp(key))
          ? value.plain
          : value)
      as R;
}