Skip to content

Commit 1013b97

Browse files
authored
Adds ability to push data to custom import
1 parent 13f78d8 commit 1013b97

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ You can customise the form by using the `beforeUploadField` and `afterUploadFiel
153153
'status' => $defaultStatus
154154
]);
155155

156+
// When adding the custom import data, the data will be available in
157+
// the custom import as $this->customImport data, when the custom import extends the
158+
// Default import.
159+
$excelImportAction->customImportData([
160+
'other_details' => [ 1, 2, 3, 4],
161+
'age' => 5
162+
]);
163+
156164
// Do some other stuff with the data before importing
157165
})
158166
,

src/Concerns/HasFormActionHooks.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ trait HasFormActionHooks
1212

1313
protected array $additionalData = [];
1414

15+
protected array $customImportData = [];
16+
1517
public function additionalData(array $data): static
1618
{
1719
$this->additionalData = $data;
1820

1921
return $this;
2022
}
2123

24+
public function customImportData(array $data): static
25+
{
26+
$this->customImportData = $data;
27+
28+
return $this;
29+
}
30+
2231
public function beforeImport(Closure $closure): static
2332
{
2433
$this->beforeImportClosure = $closure;

src/DefaultImport.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
class DefaultImport implements ToCollection, WithHeadingRow
1111
{
1212
protected array $additionalData = [];
13+
14+
protected array $customImportData = [];
1315

1416
protected ?Closure $collectionMethod = null;
1517

@@ -25,6 +27,11 @@ public function setAdditionalData(array $additionalData): void
2527
{
2628
$this->additionalData = $additionalData;
2729
}
30+
31+
public function setCustomImportData(array $customImportData): void
32+
{
33+
$this->customImportData = $customImportData;
34+
}
2835

2936
public function setCollectionMethod(Closure $closure): void
3037
{

src/ExcelImportAction.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ private function importData(): Closure
7676
$importObject->setAdditionalData($this->additionalData);
7777
}
7878

79+
if(method_exists($importObject, 'setCustomImportData') && isset($this->customImportData)) {
80+
$importObject->setCustomImportData($this->customImportData);
81+
}
82+
7983
if(method_exists($importObject, 'setCollectionMethod') && isset($this->collectionMethod)) {
8084
$importObject->setCollectionMethod($this->collectionMethod);
8185
}

0 commit comments

Comments
 (0)