<?php

namespace App\Models\Dsm;

use Illuminate\Database\Eloquent\Model;

/**
 * @property int class_data_id
 * @property int class_id
 * @property string class_a
 * @property mixed start_date
 * @property mixed end_date
 * @property mixed sign_up_date
 * @property null|mixed pen_date
 * @property int person
 * @property null|string memo
 * @property int key_users
 * @property \Carbon\Carbon key_stamp
 * @property int mod_users
 * @property mixed mod_stamp
 * @property string close
 */
class ClassData extends Model
{
    protected $connection = 'dsm';

    protected $table = 'class_data';

    protected $guarded = [];

    protected $primaryKey = 'class_data_id';

    public $timestamps = false;

    public $incrementing = false;

    public function getbirthAttribute($value)
    {
        if(empty($value))
        {
            return "";
        }
        else
        {
            return (substr($value,0,4)-1911).substr($value,4);
        }
    }

    public function student(){
        return $this->hasMany(Student::class,'class_data_id','class_data_id');
    }

    public function class(){
        return $this->belongsTo(Clas::class,'class_id','class_id');
    }

    public function keyuser()
    {
        return $this->belongsTo(User::class,'key_users','users_id');
    }

    public function moduser()
    {
        return $this->belongsTo(User::class,'mod_users','users_id');
    }

    public function classtimes()
    {
        return $this->belongsToMany(ClassTime::class);
    }

    public function gov(){
        return $this->belongsTo(Gov::class, 'gov_id', 'id');
    }

}
