diff --git a/src/Rules/TokenUploadNotExistInBeam.php b/src/Rules/TokenUploadNotExistInBeam.php index 2b667c5..bd53c31 100644 --- a/src/Rules/TokenUploadNotExistInBeam.php +++ b/src/Rules/TokenUploadNotExistInBeam.php @@ -2,14 +2,18 @@ namespace Enjin\Platform\Beam\Rules; +use Enjin\Platform\Beam\Rules\Traits\HasDataAwareRule; use Enjin\Platform\Beam\Rules\Traits\IntegerRange; +use Illuminate\Contracts\Validation\DataAwareRule; use Illuminate\Contracts\Validation\Rule; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; use Illuminate\Support\LazyCollection; -class TokenUploadNotExistInBeam implements Rule +class TokenUploadNotExistInBeam implements DataAwareRule, Rule { use IntegerRange; + use HasDataAwareRule; public function __construct(protected ?Model $beam = null) { @@ -37,7 +41,7 @@ public function passes($attribute, $value) fclose($handle); }); - $prepare = TokensDoNotExistInBeam::prepareStatement($this->beam); + $prepare = TokensDoNotExistInBeam::prepareStatement($this->beam, Arr::get($this->data, 'collectionId')); foreach ($tokens->chunk(1000) as $tokenIds) { $integers = collect($tokenIds)->filter(fn ($val) => false === $this->integerRange($val))->all(); if ($integers) { diff --git a/src/Rules/TokensDoNotExistInBeam.php b/src/Rules/TokensDoNotExistInBeam.php index f27cb11..2c9072c 100644 --- a/src/Rules/TokensDoNotExistInBeam.php +++ b/src/Rules/TokensDoNotExistInBeam.php @@ -3,15 +3,19 @@ namespace Enjin\Platform\Beam\Rules; use Enjin\Platform\Beam\Models\BeamClaim; +use Enjin\Platform\Beam\Rules\Traits\HasDataAwareRule; use Enjin\Platform\Beam\Rules\Traits\IntegerRange; use Enjin\Platform\Enums\Substrate\TokenMintCapType; +use Illuminate\Contracts\Validation\DataAwareRule; use Illuminate\Contracts\Validation\Rule; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; -class TokensDoNotExistInBeam implements Rule +class TokensDoNotExistInBeam implements DataAwareRule, Rule { use IntegerRange; + use HasDataAwareRule; public function __construct(protected ?Model $beam = null) { @@ -27,7 +31,7 @@ public function __construct(protected ?Model $beam = null) */ public function passes($attribute, $value) { - $prepare = static::prepareStatement($this->beam); + $prepare = static::prepareStatement($this->beam, Arr::get($this->data, 'collectionId')); $integers = collect($value)->filter(fn ($val) => false === $this->integerRange($val))->all(); if ($integers) { if ($prepare->whereIn('beam_claims.token_chain_id', $integers)->exists()) { @@ -48,15 +52,17 @@ public function passes($attribute, $value) /** * Prepare the statement to check if the token ids exist in the beam. */ - public static function prepareStatement(?Model $beam): Builder + public static function prepareStatement(?Model $beam, ?string $collectionId = null): Builder { + $collectionId = Arr::get($beam, 'collection_chain_id', $collectionId); + return BeamClaim::whereHas('beam', fn ($query) => $query->where('end', '>', now())) ->join( 'collections', fn ($join) => $join->on('collections.id', '=', 'beam_claims.collection_id') ->when( - $beam, - fn ($query) => $query->where('collections.collection_chain_id', $beam->collection_chain_id) + $collectionId, + fn ($query) => $query->where('collections.collection_chain_id', $collectionId) ) )->leftJoin( 'tokens',