From a582fa7cd9d703d4350142be3f4eea9ce833f880 Mon Sep 17 00:00:00 2001 From: Scott-David Jones <57994086+Scott-DavidJones@users.noreply.github.com> Date: Mon, 8 Jun 2020 20:57:18 +0100 Subject: [PATCH] Allow passing of additional relationship data new function to allow user to pass an array of additional relationship data to set. --- src/MultiSelect.php | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 ); }; }