<?php

namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;

class RegularActivityExport implements FromArray,WithHeadings
{
    protected $activities;
    public function __construct($activities)
    {
        $this->activities = $activities;
    }

    public function headings(): array
    {
        return [
            ['标题','日期', '签到码', '创建时间']
        ];
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function array():array
    {
        $items = [];
        foreach ($this->activities as $activity){
            $items[] = [
                $activity->title,
                $activity->date,
                $activity->sign_qrcode,
                $activity->created_at->toDateTimeString(),
            ];
        }
        return $items;
    }
}
