@@ -18,15 +18,15 @@ trait HasAttributes
1818 /**
1919 * The cache of the casts.
2020 */
21- protected static ? array $ castsCache = null ;
21+ protected static array $ castsCache = [] ;
2222
2323 /**
2424 * Resolve the custom caster class for a given key.
2525 */
2626 protected function resolveCasterClass (string $ key ): CastsAttributes |CastsInboundAttributes
2727 {
2828 $ castType = $ this ->getCasts ()[$ key ];
29- if ($ caster = static ::$ casterCache [$ castType ] ?? null ) {
29+ if ($ caster = static ::$ casterCache [static ::class][ $ castType ] ?? null ) {
3030 return $ caster ;
3131 }
3232
@@ -45,26 +45,26 @@ protected function resolveCasterClass(string $key): CastsAttributes|CastsInbound
4545 }
4646
4747 if (is_object ($ castClass )) {
48- return static ::$ casterCache [$ castType ] = $ castClass ;
48+ return static ::$ casterCache [static ::class][ $ castType ] = $ castClass ;
4949 }
5050
51- return static ::$ casterCache [$ castType ] = new $ castClass (...$ arguments );
51+ return static ::$ casterCache [static ::class][ $ castType ] = new $ castClass (...$ arguments );
5252 }
5353
5454 /**
5555 * Get the casts array.
5656 */
5757 public function getCasts (): array
5858 {
59- if (! is_null (static ::$ castsCache )) {
60- return static :: $ castsCache ;
59+ if (! is_null ($ cache = static ::$ castsCache[ static ::class] ?? null )) {
60+ return $ cache ;
6161 }
6262
6363 if ($ this ->getIncrementing ()) {
64- return static ::$ castsCache = array_merge ([$ this ->getKeyName () => $ this ->getKeyType ()], $ this ->casts , $ this ->casts ());
64+ return static ::$ castsCache[ static ::class] = array_merge ([$ this ->getKeyName () => $ this ->getKeyType ()], $ this ->casts , $ this ->casts ());
6565 }
6666
67- return static ::$ castsCache = $ this ->casts ;
67+ return static ::$ castsCache[ static ::class] = $ this ->casts ;
6868 }
6969
7070 /**
0 commit comments