<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DB;
class CarExchangeCategory extends Model{
    use HasFactory;
    protected $table = 'car_exchange_category';
    
    protected $fillable = [
        'name',
        'status',
        'created_by',
        'created_at',
        'updated_by',
        'updated_at' 
    ];

    public function export($slug){
        $collection = DB::table('car_exchange_category')
                        ->select('name','status');

        /*$collection = DB::table('exteriorcolor')
                        ->select('exteriorcolor.name', 'colortone.name as colortone_name','exteriorcolor.status')
                        ->leftjoin('colortone' ,'colortone.id' ,'exteriorcolor.tone_selection');*/

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