Skip to content

Commit

Permalink
Fix getKeyName
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarpsvo committed Feb 27, 2024
1 parent d42f331 commit aec59f3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Multiselect.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,16 @@ public function setOptionsFromModels(Collection $models, $resourceClass)
return $this->options(
$models
->mapInto($resourceClass)
->filter()
->mapWithKeys(function ($associatedResource) {
$keyName = $this->keyName ?? $associatedResource->getKeyName();
$keyName = $this->keyName ?? $associatedResource->getKeyName() ?? null;
if (!$keyName) return null;

$resourceKey = $associatedResource->{$keyName};

return [$resourceKey => $associatedResource->title()];
})
->filter()
->values()
);
}

Expand Down

0 comments on commit aec59f3

Please sign in to comment.