<?php

namespace App\Models;

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

class Teammaster extends Model{
    use HasFactory;
    protected $table = 'Team_master';
    
    protected $fillable = [
        'team_name',
        'branch_name',
        'department',
        'status',
        'created_by',
        'created_at',
        'updated_by',
        'updated_at',
    ];
    
    const ACTIVE = 'active';
    const INACTIVE = 'inactive';
    const DELETED = 'deleted';

    public function export($slug){
        $collection = DB::table('Team_master')
                        ->select('Team_master.team_name', 'department.name as department_name', 'branches.name as branch_name_new', 'Team_master.status')
                        ->leftjoin('department' ,'department.id' ,'Team_master.department')
                        ->leftjoin('branches' ,'branches.id' ,'Team_master.branch_name');

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