{"record":{"id":"b4e3d18b9f948b88","repo":"laravel/framework","slug":"the-provided-class-must-extend-illuminate-support-b4e3d1","errorCode":null,"errorMessage":"The provided class must extend [Illuminate\\Support\\Collection].","messagePattern":"The provided class must extend \\[Illuminate\\\\Support\\\\Collection\\]\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Eloquent/Casts/AsEncryptedCollection.php","lineNumber":36,"sourceCode":"     * @return \\Illuminate\\Contracts\\Database\\Eloquent\\CastsAttributes<\\Illuminate\\Support\\Collection<array-key, mixed>, iterable>\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function castUsing(array $arguments)\n    {\n        return new class($arguments) implements CastsAttributes\n        {\n            public function __construct(protected array $arguments)\n            {\n                $this->arguments = array_pad(array_values($this->arguments), 2, '');\n            }\n\n            public function get($model, $key, $value, $attributes)\n            {\n                $collectionClass = empty($this->arguments[0]) ? Collection::class : $this->arguments[0];\n\n                if (! is_a($collectionClass, Collection::class, true)) {\n                    throw new InvalidArgumentException('The provided class must extend ['.Collection::class.'].');\n                }\n\n                if (! isset($attributes[$key])) {\n                    return null;\n                }\n\n                $instance = new $collectionClass(Json::decode(Crypt::decryptString($attributes[$key])));\n\n                if (! isset($this->arguments[1]) || ! $this->arguments[1]) {\n                    return $instance;\n                }\n\n                if (is_string($this->arguments[1])) {\n                    $this->arguments[1] = Str::parseCallback($this->arguments[1]);\n                }\n\n                return is_callable($this->arguments[1])\n                    ? $instance->map($this->arguments[1])","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Eloquent/Casts/AsEncryptedCollection.php#L18-L54","documentation":"Thrown by the AsEncryptedCollection cast (the encrypted variant of AsCollection) when the first argument does not extend Illuminate\\Support\\Collection. The anonymous cast class validates the collection class with is_a(..., true) before decrypting and wrapping the JSON payload, so a non-Collection class is rejected before any decryption work happens.","triggerScenarios":"Declaring AsEncryptedCollection::class . ':' . SomeClass::class where SomeClass is not a Collection subclass. Triggered when reading the encrypted attribute (get()), which runs the is_a() check before decrypting via Crypt::decryptString and constructing the collection.","commonSituations":"Switching an attribute from AsCollection to AsEncryptedCollection but keeping a custom class that was never made a Collection subclass; referencing a class that was deleted or renamed; using a third-party collection wrapper that does not extend the base Collection.","solutions":["Confirm the first argument class extends Illuminate\\Support\\Collection with is_subclass_of().","Correct the fully-qualified class name / import in the cast string.","Use AsEncryptedCollection::class with no custom class argument to fall back to the base Collection.","Extend Collection in your custom class if you need specialized behavior."],"exampleFix":"// before\nprotected $casts = [\n    'secret_list' => AsEncryptedCollection::class . ':' . App\\DTO\\SecretList::class,\n];\n\n// after\nclass SecretList extends \\Illuminate\\Support\\Collection {}\n\nprotected $casts = [\n    'secret_list' => AsEncryptedCollection::class . ':' . App\\DTO\\SecretList::class,\n];","handlingStrategy":"validation","validationCode":"use Illuminate\\Support\\Collection;\n\n$class = App\\Support\\SecretList::class;\nif (! is_subclass_of($class, Collection::class)) {\n    throw new \\LogicException(\"{$class} must extend \\\\Illuminate\\\\Support\\\\Collection\");\n}\n// safe to reference in cast string: AsEncryptedCollection::class . ':' . $class","typeGuard":"function isValidCollectionClass(string $class): bool\n{\n    return class_exists($class) && is_subclass_of($class, \\Illuminate\\Support\\Collection::class);\n}","tryCatchPattern":null,"preventionTips":["Mark every custom collection class as `extends \\Illuminate\\Support\\Collection`.","Use the ::class constant in the cast string to catch typos at static-analysis time.","Keep the encryption key and collection class consistent across environments."],"tags":["eloquent","cast","collection","encryption","configuration"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}