File tree Expand file tree Collapse file tree 2 files changed +49
-37
lines changed
Expand file tree Collapse file tree 2 files changed +49
-37
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Yajra\DataTables\Exports;
4+
5+ use Illuminate\Support\Collection;
6+ use Maatwebsite\Excel\Concerns\Exportable;
7+ use Maatwebsite\Excel\Concerns\FromCollection;
8+ use Maatwebsite\Excel\Concerns\WithHeadings;
9+
10+ abstract class DataTablesCollectionExport implements FromCollection, WithHeadings
11+ {
12+ use Exportable;
13+
14+ /**
15+ * @var Collection
16+ */
17+ protected $collection;
18+
19+ /**
20+ * @param Collection $collection
21+ */
22+ public function __construct(Collection $collection)
23+ {
24+ $this->collection = $collection;
25+ }
26+
27+ /**
28+ * @return Collection
29+ */
30+ public function collection()
31+ {
32+ return $this->collection;
33+ }
34+
35+ /**
36+ * @return array
37+ */
38+ public function headings(): array
39+ {
40+ $first = $this->collection->first();
41+ if ($first) {
42+ return array_keys($first);
43+ }
44+
45+ return [];
46+ }
47+ }
Original file line number Diff line number Diff line change 66use Maatwebsite \Excel \Concerns \Exportable ;
77use Maatwebsite \Excel \Concerns \FromCollection ;
88use Maatwebsite \Excel \Concerns \WithHeadings ;
9+ use Yajra \DataTables \Exports \DataTablesCollectionExport ;
910
10- class DataTablesExportHandler implements FromCollection, WithHeadings
11+ class DataTablesExportHandler extends DataTablesCollectionExport
1112{
12- use Exportable;
1313
14- /**
15- * @var Collection
16- */
17- protected $ collection ;
18-
19- /**
20- * DataTablesExportHandler constructor.
21- *
22- * @param Collection $collection
23- */
24- public function __construct (Collection $ collection )
25- {
26- $ this ->collection = $ collection ;
27- }
28-
29- /**
30- * @return Collection
31- */
32- public function collection ()
33- {
34- return $ this ->collection ;
35- }
36-
37- /**
38- * @return array
39- */
40- public function headings (): array
41- {
42- $ first = $ this ->collection ->first ();
43- if ($ first ) {
44- return array_keys ($ first );
45- }
46-
47- return [];
48- }
4914}
You can’t perform that action at this time.
0 commit comments