55use Laravel \Nova \Resource ;
66use Maatwebsite \Excel \Concerns \ToModel ;
77use Maatwebsite \Excel \Concerns \Importable ;
8+ use Maatwebsite \Excel \Concerns \SkipsErrors ;
9+ use Maatwebsite \Excel \Concerns \SkipsOnError ;
10+ use Maatwebsite \Excel \Concerns \SkipsFailures ;
11+ use Maatwebsite \Excel \Concerns \SkipsOnFailure ;
812use Maatwebsite \Excel \Concerns \WithHeadingRow ;
913use Maatwebsite \Excel \Concerns \WithValidation ;
14+ use Maatwebsite \Excel \Concerns \WithBatchInserts ;
15+ use Maatwebsite \Excel \Concerns \WithChunkReading ;
1016
11- class Importer implements ToModel, WithValidation, WithHeadingRow
17+ class Importer implements ToModel, WithValidation, WithHeadingRow, WithBatchInserts, WithChunkReading, SkipsOnFailure, SkipsOnError
1218{
13- use Importable;
19+ use Importable, SkipsFailures, SkipsErrors ;
1420
1521 /** @var Resource */
1622 protected $ resource ;
@@ -19,6 +25,31 @@ class Importer implements ToModel, WithValidation, WithHeadingRow
1925 protected $ rules ;
2026 protected $ model_class ;
2127
28+ public function model (array $ row )
29+ {
30+ [$ model , $ callbacks ] = $ this ->resource ::fill (
31+ new ImportRequest ($ this ->mapRowDataToAttributes ($ row )),
32+ $ this ->resource ::newModel ()
33+ );
34+
35+ return $ model ;
36+ }
37+
38+ public function rules (): array
39+ {
40+ return $ this ->rules ;
41+ }
42+
43+ public function batchSize (): int
44+ {
45+ return 100 ;
46+ }
47+
48+ public function chunkSize (): int
49+ {
50+ return 100 ;
51+ }
52+
2253 /**
2354 * @return mixed
2455 */
@@ -57,11 +88,6 @@ public function setAttributeMap($map)
5788 return $ this ;
5889 }
5990
60- public function rules (): array
61- {
62- return $ this ->rules ;
63- }
64-
6591 /**
6692 * @param mixed $rules
6793 * @return Importer
@@ -92,16 +118,6 @@ public function setModelClass($model_class)
92118 return $ this ;
93119 }
94120
95- public function model (array $ row )
96- {
97- [$ model , $ callbacks ] = $ this ->resource ::fill (
98- new ImportRequest ($ this ->mapRowDataToAttributes ($ row )),
99- $ this ->resource ::newModel ()
100- );
101-
102- return $ model ;
103- }
104-
105121 public function setResource ($ resource )
106122 {
107123 $ this ->resource = $ resource ;
0 commit comments