Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/Filament/Resources/EventAchievementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\EventAchievement;
use App\Models\Game;
use App\Models\User;
use Closure;
use Filament\Forms;
use Filament\Infolists;
use Filament\Pages\Page;
Expand Down Expand Up @@ -167,6 +168,17 @@ public static function form(Schema $schema): Schema
}

return $label;
})
->rule(function (): Closure {
return function (string $attribute, mixed $value, Closure $fail): void {
if ($value === null) {
return;
}

if (EventAchievement::where('achievement_id', (int) $value)->exists()) {
$fail('Source achievement cannot be an event achievement.');
}
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we ever want to allow any event achievement to depend on another event achievement? Should the restriction just be "source achievement cannot be event achievement"?

Otherwise, we could still end up with an infinite loop if any achievement in the chain pointed back to the start node: A -> B -> C -> A

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

I've reverted most of the original implementation in latest (let's just treat it as a data issue if it happens in prod somehow) and tightened this rule.

}),

Forms\Components\DatePicker::make('active_from')
Expand Down
Loading