<?php

namespace App\Exports;

use App\Models\rto_master;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
class ExportRTO implements FromCollection, WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
     function __construct($slug) {
        $this->slug = $slug;
    }

    public function collection()
    {
        //return rto_master::all();
        //return rto_master::select('rto_master.id as id','car_model.name as car_model_name','car_varient.name','pricelist_master.price_list_name','rto_master.amount','rto_master.status','branches.name as branch_name')->leftjoin('car_model','car_model.id','=','rto_master.car_model_id')->leftjoin('car_varient','car_varient.id','=','rto_master.car_varient_id')->leftjoin('pricelist_master','pricelist_master.id','=','rto_master.pricelist_id')->leftjoin('branches','branches.id','=','rto_master.branch_id')->get();

        $user = new rto_master();
        $data = $user->export($this->slug);

        if($data == null){
            return throw new \ErrorException('No Data Found!');
        }else{
            return $data;
        }
    }
    public function headings() :array{
        return ['Sr.No','Car Model Name','Car Varient Name','Pricelist Name' ,'Amount','Branch','Status'];
    }
}
