<?php
namespace App\Exports;
use App\Models\Ward;

use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use DB;

class WardsExport implements FromCollection, WithHeadings
{
	public $wards;

    public function __construct($wards) {
        $this->wards = $wards;
    }

    public function collection()
    {
        $wards=Ward::query()
						->join('subcounties','subcounties.SubCountyID','=','wards.SubCountyID')
						->whereIn('WardID', $this->wards)
						->select('WardID','WardName','SubCountyName','wards.CreatedAt')
						->get();
						
		return $wards;
    }
	
	public function headings(): array
    {
        //return ["heading_1", "heading_2", "heading_3"];
		return array_keys($this->collection()->first()->toArray());
    }
}