Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor
  • Loading branch information
pascalbaljet committed Dec 15, 2020
commit 5958dd8bccfbc553ac955103e113f5e46726ec68
8 changes: 6 additions & 2 deletions src/Components/HandlesBoundValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ private function findOptionsFromRelation($bind, string $name)
$relation = $bind->{$name}();

if ($relation instanceof BelongsToMany) {
$related = $relation->getRelated();

$relatedKeyName = $relation->getRelatedKeyName();

return $relation->getBaseQuery()
->get($relation->getQualifiedRelatedKeyName())
->pluck($relation->getRelatedKeyName())
->get($related->qualifyColumn($relatedKeyName))
->pluck($relatedKeyName)
->all();
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SelectRelationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function it_shows_the_slot_if_the_options_are_empty()

$post->comments()->sync([$commentA->getKey(), $commentC->getKey()]);

$options = Comment::get()->keyBy->id->map->content;
$options = Comment::get()->pluck('content', 'id');

Route::get('select-relation', function () use ($post, $options) {
return view('select-relation')
Expand Down