Skip to content

Commit

Permalink
relation fixe
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Sep 25, 2023
1 parent 3670477 commit 7074b1c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Form/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany as EloquentRelation;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\App;

class BelongsToMany extends Relation
Expand All @@ -28,6 +29,7 @@ public function __construct(Form $form, string $label, string $modelAttribute =
parent::__construct($form, $label, $modelAttribute, $relation);

$this->setAttribute('multiple', true);
$this->name($this->modelAttribute.'[]');
}

/**
Expand Down Expand Up @@ -139,6 +141,8 @@ public function resolveHydrate(Request $request, mixed $value): void
$this->hydrateResolver = function (Request $request, Model $model, mixed $value): void {
$value = (array) $value;

$value = Arr::isList($value) ? array_fill_keys($value, []) : $value;

$relation = $this->getRelation();

$results = $this->resolveRelatableQuery($request)
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public function resolveOptions(Request $request): array
}, function (Collection $collection) use ($mapCallback): Collection {
return $collection->map($mapCallback);
})
->toArray();
->all();
}

/**
Expand Down

0 comments on commit 7074b1c

Please sign in to comment.