File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 66use Illuminate \Support \Str ;
77use SimonHamp \LaravelNovaCsvImport \Contracts \Modifier ;
88use SimonHamp \LaravelNovaCsvImport \Modifiers \Boolean ;
9+ use SimonHamp \LaravelNovaCsvImport \Modifiers \DefaultValue ;
910use SimonHamp \LaravelNovaCsvImport \Modifiers \ExcelDate ;
1011use SimonHamp \LaravelNovaCsvImport \Modifiers \Hash ;
1112use SimonHamp \LaravelNovaCsvImport \Modifiers \Prefix ;
@@ -23,6 +24,7 @@ protected function bootHasModifiers()
2324 // Register built-in modifiers
2425 static ::registerModifiers (
2526 new Boolean ,
27+ new DefaultValue ,
2628 new ExcelDate ,
2729 new StrModifier ,
2830 new Hash ,
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace SimonHamp \LaravelNovaCsvImport \Modifiers ;
4+
5+ use SimonHamp \LaravelNovaCsvImport \Contracts \Modifier ;
6+
7+ class DefaultValue implements Modifier
8+ {
9+ public function title (): string
10+ {
11+ return 'Default Value ' ;
12+ }
13+
14+ public function description (): string
15+ {
16+ return "Set a default value for the field if the CSV column is empty or missing " ;
17+ }
18+
19+ public function settings (): array
20+ {
21+ return [
22+ 'string ' => [
23+ 'type ' => 'string ' ,
24+ 'title ' => 'Default Value ' ,
25+ ],
26+ ];
27+ }
28+
29+ public function handle ($ value = null , array $ settings = []): string
30+ {
31+ return empty ($ value ) ? $ settings ['string ' ] : $ value ;
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments