<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DB;

class Sublead extends Model{
    use HasFactory;
    protected $table = 'sub_lead';
    
    protected $fillable = [
        'lead_id',
        'name',
        'status',
        'created_by',
        'created_at',
        'updated_by',
        'updated_at'
    ];

    public function export($slug){
        $collection = DB::table('sub_lead')->select('lead.name', 'sub_lead.name as sub_lead_name','sub_lead.status')->leftjoin('lead' ,'lead.id' ,'sub_lead.lead_id');

        if($slug != 'all')
            $collection->where(['status' => $slug]);
        
        $data = $collection->get();
        
        if($data->isNotEmpty()){
            return $data;
        }else{
            return null;
        }
    }
}
