diff --git a/src/MultiSelect.php b/src/MultiSelect.php index 106f204..9c6822f 100644 --- a/src/MultiSelect.php +++ b/src/MultiSelect.php @@ -40,6 +40,12 @@ class MultiSelect extends Field * @var int */ private $maxItems; + + /** + * additional attachment data + * @var mixed + */ + private $attachmentData = null; public function options($value) { @@ -76,6 +82,19 @@ public function maxItems(int $maxItems) return $this; } + + /** + * Pass additional fields to the relationship for attachement. + * + * @param array $attachmentData + * @return $this + */ + public function attachAdditionalRelationData(array $attachmentData) + { + $this->attachmentData = $attachmentData; + + return $this; + } public function meta() { @@ -118,8 +137,13 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib $relation->detach($currentRelationIds->diff($requestIds)->all()); // figure out whats left, and attach them + $toAttachArray = []; + if (null !== $this->attachmentData) { + $toAttachArray = $this->attachmentData; + } $relation->attach( - $requestIds->diff($currentRelationIds)->all() + $requestIds->diff($currentRelationIds)->all(), + $toAttachArray ); }; }