<?php

namespace App\Models;

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

class CNGKit extends Model{
    use HasFactory;
    protected $table = 'cng_kit';
    
    protected $fillable = [
        'name',
        'amount',
        'company',
        'kg',
        'status',
        'created_by',
        'created_at',
        'updated_by',
        'updated_at'
    ];

    public function export($slug){
        $collection = DB::table('cng_kit')
                        ->select('cng_kit.name', 'cng_kit.amount', 'cng_kit.company', 'cng_kit.kg','cng_kit.status');

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