diff --git a/src/GraphQL/Types/BeamClaimType.php b/src/GraphQL/Types/BeamClaimType.php index 8a1b8c9..b8de5f0 100644 --- a/src/GraphQL/Types/BeamClaimType.php +++ b/src/GraphQL/Types/BeamClaimType.php @@ -73,7 +73,7 @@ public function fields(): array 'code' => [ 'type' => GraphQL::type('String!'), 'description' => __('enjin-platform-beam::type.beam_claim.field.code'), - 'resolve' => fn ($claim) => $claim->singleUseCode, + 'resolve' => fn ($claim) => $claim->code ? $claim->singleUseCode : '', ], 'identifierCode' => [ 'type' => GraphQL::type('String!'), diff --git a/src/Models/Laravel/BeamClaim.php b/src/Models/Laravel/BeamClaim.php index 6a309e0..150e0f2 100644 --- a/src/Models/Laravel/BeamClaim.php +++ b/src/Models/Laravel/BeamClaim.php @@ -151,7 +151,7 @@ public function scopeWithSingleUseCode(Builder $query, string $code): Builder public function singleUseCode(): Attribute { return Attribute::make( - get: fn () => encrypt(implode(':', [$this->code, $this->beam->code, $this->nonce])) + get: fn () => encrypt(implode(':', [$this->code, $this->beam?->code, $this->nonce])) ); } diff --git a/src/Models/Laravel/Traits/EagerLoadSelectFields.php b/src/Models/Laravel/Traits/EagerLoadSelectFields.php index 8b5a923..8c110ca 100644 --- a/src/Models/Laravel/Traits/EagerLoadSelectFields.php +++ b/src/Models/Laravel/Traits/EagerLoadSelectFields.php @@ -148,7 +148,10 @@ public static function loadClaims( ]; } - foreach (BeamClaimType::getRelationFields($fieldKeys) as $relation) { + foreach ([ + ...BeamClaimType::getRelationFields($fieldKeys), + ...(isset($fields['code']) ? ['beam'] : []), + ] as $relation) { $with = array_merge( $with, static::getRelationQuery(