99use Illuminate \Bus \Queueable ;
1010use Illuminate \Contracts \Queue \ShouldBeUnique ;
1111use Illuminate \Contracts \Queue \ShouldQueue ;
12- use Illuminate \Contracts \ Support \ Arrayable ;
12+ use Illuminate \Database \ Eloquent \ Model ;
1313use Illuminate \Foundation \Bus \Dispatchable ;
1414use Illuminate \Http \File ;
1515use Illuminate \Queue \InteractsWithQueue ;
@@ -125,12 +125,6 @@ public function handle(): void
125125 foreach ($ query as $ row ) {
126126 $ cells = [];
127127
128- $ row = $ row instanceof Arrayable ? $ row ->toArray () : (array ) $ row ;
129-
130- if ($ this ->usesLazyMethod () && is_array ($ row )) {
131- $ row = Arr::dot ($ row );
132- }
133-
134128 $ defaultDateFormat = 'yyyy-mm-dd ' ;
135129 if (config ('datatables-export.default_date_format ' )
136130 && is_string (config ('datatables-export.default_date_format ' ))
@@ -147,7 +141,7 @@ public function handle(): void
147141 }
148142
149143 /** @var array|bool|int|string|null|DateTimeInterface $value */
150- $ value = $ row[ $ property] ?? '' ;
144+ $ value = $ this -> getValue ( $ row, $ property) ?? '' ;
151145
152146 if (isset ($ column ->exportRender )) {
153147 $ callback = $ column ->exportRender ;
@@ -231,6 +225,24 @@ protected function getExportableColumns(DataTable $dataTable): Collection
231225 return $ columns ->filter (fn (Column $ column ) => $ column ->exportable );
232226 }
233227
228+ protected function getValue (array |Model $ row , string $ property ): mixed
229+ {
230+ [$ currentProperty , $ glue , $ childProperty ] = array_pad (preg_split ('/\[(.*?)\]\.?/ ' , $ property , 2 , PREG_SPLIT_DELIM_CAPTURE ), 3 , null );
231+
232+ if ($ glue === '' ) {
233+ $ glue = ', ' ;
234+ }
235+
236+ /** @var string $currentProperty */
237+ $ value = data_get ($ row , $ currentProperty .($ childProperty ? '.* ' : '' ));
238+
239+ if ($ childProperty ) {
240+ $ value = Arr::map ($ value , fn ($ v ) => $ this ->getValue ($ v , $ childProperty ));
241+ }
242+
243+ return $ glue ? Arr::join ($ value , $ glue ) : $ value ;
244+ }
245+
234246 protected function usesLazyMethod (): bool
235247 {
236248 return config ('datatables-export.method ' , 'lazy ' ) === 'lazy ' ;
0 commit comments