{"id":"fcb420faadab9ec3","repo":"laravel/framework","slug":"unsupported-binary-codec-format-s-allowed-form","errorCode":null,"errorMessage":"Unsupported binary codec format [%s]. Allowed formats are: %s.","messagePattern":"Unsupported binary codec format \\[(.+?)\\]\\. Allowed formats are: (.+?)\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/Casts/AsBinary.php","lineNumber":32,"sourceCode":"     *\n     * @param  array{string}  $arguments\n     * @return \\Illuminate\\Contracts\\Database\\Eloquent\\CastsAttributes\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function castUsing(array $arguments)\n    {\n        return new class($arguments) implements CastsAttributes\n        {\n            protected string $format;\n\n            public function __construct(protected array $arguments)\n            {\n                $this->format = $this->arguments[0]\n                    ?? throw new InvalidArgumentException('The binary codec format is required.');\n\n                if (! in_array($this->format, BinaryCodec::formats(), true)) {\n                    throw new InvalidArgumentException(sprintf(\n                        'Unsupported binary codec format [%s]. Allowed formats are: %s.',\n                        $this->format,\n                        implode(', ', BinaryCodec::formats()),\n                    ));\n                }\n            }\n\n            public function get($model, $key, $value, $attributes)\n            {\n                return BinaryCodec::decode($attributes[$key] ?? null, $this->format);\n            }\n\n            public function set($model, $key, $value, $attributes)\n            {\n                return [$key => BinaryCodec::encode($value, $this->format)];\n            }\n        };\n    }","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Database/Eloquent/Casts/AsBinary.php#L14-L50","documentation":"Thrown by AsBinary::castUsing()'s caster when the supplied format string is not one returned by BinaryCodec::formats(). The whitelist (e.g. 'uuid', 'ulid', plus any user-registered formats) keeps binary encoding deterministic; an unknown format is rejected.","triggerScenarios":"Declaring a cast like 'binary:guid', 'binary:base64', or any string not in BinaryCodec::formats(). The caster's in_array check fails and the sprintf message lists the allowed set.","commonSituations":"Guessing a format name; pre-registering a custom format on a different BinaryCodec instance; version mismatch where a format was renamed; typo in the cast string.","solutions":["Use one of the formats listed in the error message (typically 'uuid' or 'ulid').","Register your custom format with BinaryCodec before loading models: BinaryCodec::registerFormat('guid', $encoder, $decoder).","Inspect allowed formats at runtime: Illuminate\\Support\\BinaryCodec::formats().","Correct the typo / casing in the cast string."],"exampleFix":"// before\nprotected $casts = ['id' => 'binary:guid'];\n\n// after\nprotected $casts = ['id' => AsBinary::uuid()];\n// or register first:\n\\Illuminate\\Support\\BinaryCodec::registerFormat('guid', $enc, $dec);\nprotected $casts = ['id' => 'binary:guid'];","handlingStrategy":"validation","validationCode":"$format = substr($cast, strpos($cast, ':') + 1);\nif (! in_array($format, \\Illuminate\\Support\\BinaryCodec::formats(), true)) {\n    throw new \\RuntimeException(\"Unsupported binary format [$format].\");\n}","typeGuard":"function isSupportedBinaryFormat(string $format): bool {\n    return in_array($format, \\Illuminate\\Support\\BinaryCodec::formats(), true);\n}","tryCatchPattern":null,"preventionTips":["Register custom formats with BinaryCodec before model hydration.","Inspect \\Illuminate\\Support\\BinaryCodec::formats() when unsure of valid values.","Pin the framework version so format names don't change under you.","Add a boot-time config check for binary cast strings."],"tags":["eloquent","casts","binary","validation"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}