<?php

namespace App;

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

class Pengakhiran extends Model
{
    use SoftDeletes;

    public $table = 'pengakhirans';

    protected $dates = [
        'updated_at',
        'created_at',
        'deleted_at',
        'tanggal_bimbingan',
    ];

    protected $fillable = [
        'nama_id',
        'created_at',
        'updated_at',
        'deleted_at',
        'tanggal_bimbingan',
    ];

    public function nama()
    {
        return $this->belongsTo(IdentitasKlien::class, 'nama_id');
    }

    public function getTanggalBimbinganAttribute($value)
    {
        return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null;
    }

    public function setTanggalBimbinganAttribute($value)
    {
        $this->attributes['tanggal_bimbingan'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null;
    }
}
