cqpCow 1 gadu atpakaļ
vecāks
revīzija
0609d137b0
2 mainītis faili ar 57 papildinājumiem un 0 dzēšanām
  1. 27 0
      app/Exports/MultiSheetExport.php
  2. 30 0
      app/Exports/SingleSheetExport.php

+ 27 - 0
app/Exports/MultiSheetExport.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace App\Exports;
+
+
+use Maatwebsite\Excel\Concerns\WithMultipleSheets;
+
+class MultiSheetExport implements WithMultipleSheets
+{
+    protected $data;
+
+    public function __construct(array $data)
+    {
+        $this->data = $data;
+    }
+
+    public function sheets(): array
+    {
+        $sheets = [];
+
+        foreach ($this->data as $sheetName => $sheetData) {
+            $sheets[] = new SingleSheetExport($sheetData, $sheetName);
+        }
+
+        return $sheets;
+    }
+}

+ 30 - 0
app/Exports/SingleSheetExport.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Exports;
+
+
+use Maatwebsite\Excel\Concerns\FromCollection;
+use Maatwebsite\Excel\Concerns\WithTitle;
+use Illuminate\Support\Collection;
+
+class SingleSheetExport implements FromCollection,WithTitle
+{
+    protected $data;
+    protected $sheetName;
+
+    public function __construct(array $data, string $sheetName)
+    {
+        $this->data = $data;
+        $this->sheetName = $sheetName;
+    }
+
+    public function collection()
+    {
+        return new Collection($this->data);
+    }
+
+    public function title(): string
+    {
+        return $this->sheetName;
+    }
+}