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

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

class ActivityLogExport implements FromCollection, WithHeadings
{
	public $activitylog;

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

    public function collection()
    {
        $activitylog=ActivityLog::query()
						->join('users','users.id','=','activity_log.causer_id')
						->whereIn('activity_log.id', $this->activitylog)
						->select('activity_log.created_at as ActivityDate','description as Action','table_name as Table','subject_id as RecordID','users.name as UserID')
						->get();
						
		return $activitylog;
    }
	
	public function headings(): array
    {
        //return ["heading_1", "heading_2", "heading_3"];
		return array_keys($this->collection()->first()->toArray());
    }
}