/home/mip/mip/app/Modules/Client/Models/JobOpening/JobOpening.php
<?php

namespace QxCMS\Modules\Client\Models\JobOpening;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class JobOpening extends Model
{
    protected $connection = 'client';
    protected $table = 'job_opening';
    public $module_id = 14;
    
    protected $guarded = [];
    protected $appends = ['hashid'];

    public function getHashidAttribute()
    {
        return hashid($this->id);
    }

    public function setOpeningDateAttribute($value) 
    {
        if($value <> '') {
            $dateformats = getDateFormatConfig('set');
            return $this->attributes['opening_date'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
        }
        return $this->attributes['opening_date'] = '0000-00-00';
    }

    public function getOpeningDateAttribute($value) 
    {
        if($value <> '0000-00-00') {
            $dateformats = getDateFormatConfig('get');
            return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
        }
        return;
    }

    public function formOpeningDateAttribute($value)
    {
        if($value <> '0000-00-00') {
            $dateformats = getDateFormatConfig('form');
            return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
        }
        return;
    }

    public function setClosingDateAttribute($value) 
    {
        if($value <> '') {
            $dateformats = getDateFormatConfig('set');
            return $this->attributes['closing_date'] = Carbon::createFromFormat($dateformats['php'], $value)->format('Y-m-d');
        }
        return $this->attributes['closing_date'] = '0000-00-00';
    }

    public function getClosingDateAttribute($value) 
    {
        if($value <> '0000-00-00') {
            $dateformats = getDateFormatConfig('get');
            return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
        }
        return;
    }

    public function formClosingDateAttribute($value)
    {
        if($value <> '0000-00-00') {
            $dateformats = getDateFormatConfig('form');
            return Carbon::createFromFormat('Y-m-d', $value)->format($dateformats['php']);
        }
        return;
    }

    public function country()
    {
        return $this->belongsTo('QxCMS\Modules\Client\Models\Settings\Country', 'country_id');
    }

    public function applicants()
    {
        return $this->hasMany('QxCMS\Modules\Client\Models\Applicants\JobApplied', 'job_id');
    }
}