*/ class FilePathCast implements CastsAttributes { /** @param array $attributes */ public function get(Model $model, string $key, mixed $value, array $attributes): ?StorageFilePath { if ($value === null) { return null; } if (! is_string($value)) { throw new \InvalidArgumentException('The given value is not a valid file path string.'); } return new StorageFilePath($value); } /** @param array $attributes */ public function set(Model $model, string $key, mixed $value, array $attributes): ?string { if ($value === null) { return null; } if ($value instanceof StorageFilePath) { return $value->value; } if (is_string($value)) { return (new StorageFilePath($value))->value; } throw new \InvalidArgumentException('The given value is not a valid StorageFilePath instance or path string.'); } }