*/ class EmailCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, $value, array $attributes): Email { if ($value === null || ! is_string($value)) { throw new \UnexpectedValueException('Email must be a string.'); } return new Email($value); } /** @param array $attributes */ public function set(Model $model, string $key, $value, array $attributes): string { if ($value === null) { throw new \InvalidArgumentException('Email cannot be null.'); } if (! ($value instanceof Email)) { throw new \InvalidArgumentException('The given value is not an instance of Email.'); } return $value->value; } }