Skip to content

Commit

Permalink
[PLA-1564] Use model for scoping (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
enjinabner authored Jan 29, 2024
1 parent fd936e6 commit e1c2197
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/GraphQL/Mutations/CreateBeamMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Enjin\Platform\Beam\Rules\TokenUploadNotExistInCollection;
use Enjin\Platform\Beam\Rules\UniqueTokenIds;
use Enjin\Platform\Beam\Services\BeamService;
use Enjin\Platform\Models\Collection;
use Enjin\Platform\Rules\DistinctAttributes;
use Enjin\Platform\Rules\IsCollectionOwnerOrApproved;
use GraphQL\Type\Definition\ResolveInfo;
Expand Down Expand Up @@ -95,7 +96,16 @@ protected function rules(array $args = []): array
'image' => ['filled', 'url', 'max:1024'],
'start' => ['filled', 'date', 'before:end'],
'end' => ['filled', 'date', 'after:start'],
'collectionId' => ['bail', 'filled', 'exists:collections,collection_chain_id', new IsCollectionOwnerOrApproved()],
'collectionId' => [
'bail',
'filled',
function (string $attribute, mixed $value, Closure $fail) {
if (!Collection::where('collection_chain_id', $value)->exists()) {
$fail('validation.exists')->translate();
}
},
new IsCollectionOwnerOrApproved(),
],
'tokens' => ['bail', 'array', 'min:1', 'max:1000', new UniqueTokenIds()],
'tokens.*.attributes' => Rule::forEach(function ($value, $attribute) use ($args) {
if (empty($value)) {
Expand Down

0 comments on commit e1c2197

Please sign in to comment.