Skip to content

Commit 5b78510

Browse files
committed
Support multiple identifiers
1 parent 070c6c4 commit 5b78510

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Nova/Actions/Product/RetrieveByIdentifier.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Laravel\Nova\Actions\Action;
88
use Laravel\Nova\Actions\ActionResponse;
99
use Laravel\Nova\Fields\ActionFields;
10+
use Laravel\Nova\Fields\Boolean;
1011
use Laravel\Nova\Fields\Text;
1112
use Laravel\Nova\Http\Requests\NovaRequest;
1213

@@ -21,6 +22,19 @@ public function __construct()
2122
public function handle(ActionFields $fields, Collection $models): ActionResponse
2223
{
2324
$identifier = $fields->get('identifier');
25+
$csv = $fields->get('csv', false);
26+
27+
if ($csv) {
28+
$identifiers = array_map('trim', explode(',', $identifier));
29+
30+
foreach ($identifiers as $identifier) {
31+
if (! empty($identifier)) {
32+
RetrieveProductJob::dispatch($identifier);
33+
}
34+
}
35+
36+
return ActionResponse::message(__('Retrieving :count products', ['count' => count($identifiers)]));
37+
}
2438

2539
RetrieveProductJob::dispatch($identifier);
2640

@@ -32,6 +46,9 @@ public function fields(NovaRequest $request): array
3246
return [
3347
Text::make(__('Identifier'), 'identifier')
3448
->required(),
49+
50+
Boolean::make(__('CSV'), 'csv')
51+
->help(__('Check this if you are providing a comma-separated list of identifiers. i.e.: identifier1,identifier2')),
3552
];
3653
}
3754
}

0 commit comments

Comments
 (0)