35 lines
808 B
PHP
35 lines
808 B
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
|
|
class DataExport implements FromCollection, WithHeadings, WithMapping
|
|
{
|
|
protected $sensors;
|
|
public function __construct($sensors)
|
|
{
|
|
$this->sensors = $sensors;
|
|
}
|
|
public function collection()
|
|
{
|
|
return $this->sensors;
|
|
}
|
|
public function headings(): array
|
|
{
|
|
return ['No', 'Waktu Interval', 'Jarak Terakhir'];
|
|
}
|
|
public function map($sensor): array
|
|
{
|
|
static $no = 1;
|
|
|
|
return [
|
|
$no++,
|
|
\Carbon\Carbon::parse($sensor->interval_time)->format('Y-m-d H:i'),
|
|
number_format($sensor->last_distance, 2) . 'cm',
|
|
];
|
|
}
|
|
}
|