<?php

namespace App\Exports;

use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Contracts\View\View;

class ExportTask implements FromView
{
    /**
    * @return \Illuminate\Support\Collection
    */
    // public function collection()
    // {
    //     return Task::all();
    // }

    private $data;

    public function __construct($data)
    {
        // dd($data);
        $this->form_date       = $data['form_date'];
        $this->to_date   = $data['to_date'];
    }

    public function view(): View
    {   

        $form_date    = $this->form_date;
        $to_date      = $this->to_date;
        
        
        $data2 = User::where('user_type', 'user')->with(['payment_details'])
                  ->with(['payment_details' => function ($q) use ($form_date,$to_date)
                  {
                      $q->whereDate('created_at', '>=', $form_date);
                      $q->whereDate('created_at', '<=', $to_date);
                  }])
            ->get();

        // dd($data2);
        
        return view('custom', [
            'invoices' => $data2
        ]);
    }
}
