Filter out already used ips with the same port (#1496)

This commit is contained in:
MartinOscar 2025-07-10 08:59:46 +02:00 committed by GitHub
parent 5a7c6ac6e5
commit c5528a61f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -62,7 +62,16 @@ class AllocationsRelationManager extends RelationManager
->label(trans('admin/node.table.allocation_notes'))
->placeholder(trans('admin/node.table.no_notes')),
SelectColumn::make('ip')
->options(fn (Allocation $allocation) => collect($this->getOwnerRecord()->ipAddresses())->merge([$allocation->ip])->mapWithKeys(fn (string $ip) => [$ip => $ip]))
->options(function (Allocation $allocation) {
$ips = Allocation::where('port', $allocation->port)->pluck('ip');
return collect($this->getOwnerRecord()->ipAddresses())
->diff($ips)
->unshift($allocation->ip)
->unique()
->mapWithKeys(fn (string $ip) => [$ip => $ip])
->all();
})
->selectablePlaceholder(false)
->searchable()
->label(trans('admin/node.table.ip')),