Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save faizalanwar/f6a21ea01e4b77265d25fa59f7c88875 to your computer and use it in GitHub Desktop.
Save faizalanwar/f6a21ea01e4b77265d25fa59f7c88875 to your computer and use it in GitHub Desktop.
<?php
namespace App\Exports;
use App\Models\Otdp;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
class DataExport implements FromCollection, WithHeadings, WithTitle, WithDrawings
{
protected $requestawal;
protected $requestakhir;
function __construct($requestawal, $requestakhir)
{
$this->requestawal = $requestawal;
$this->requestakhir = $requestakhir;
}
public function collection()
{
$data = data::select(
'nama',
'ttl',
)->whereBetween('ttl', [$this->requestawal, $this->requestakhir])->get();
return $Otdp;
}
public function headings(): array
{
return [
'nama',
'ttl',
'foto',
];
}
public function title(): string
{
return 'data';
}
public function drawings()
{
$data = data::select(
'nama',
'ttl',
'foto'
)->whereBetween('ttl', [$this->requestawal, $this->requestakhir])->get();
$drawings = [];
$rowNum = 2;
foreach ($data as $row) {
$drawing = new Drawing();
if ($row->foto == null || $row->foto == "") {
$drawing->setPath(public_path('/assets/images/default.jpg'));
} else {
$drawing->setPath(public_path('/assets/uploads/images/') . $row->foto);
}
$drawing->setheight(20);
$drawing->setCoordinates('N' . $rowNum); //kolom name
$drawings[] = $drawing;
$rowNum++;
}
return $drawings;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment