<?php

namespace App\Models;

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

class Interiorcolor extends Model{
    use HasFactory;
    protected $table = 'interiorcolor';
    
    protected $fillable = [
        'name',
        'tone_selection',
        'status',
        'created_by',
        'created_at',
        'updated_by',
        'updated_at'
    ];

    public function export($slug){
        $collection = DB::table('interiorcolor')
                        ->select('interiorcolor.name', 'colortone.name as colortone_name','interiorcolor.status')
                        ->leftjoin('colortone' ,'colortone.id' ,'interiorcolor.tone_selection');

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