<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;


class Tizin extends Model
{
     protected $connection = 'mai1';
    protected $table = 'tizin';
    protected $primaryKey = 'id';
    
    protected $appends = ['title'];
    protected $hidden = [
        // "idsis",
        "jen",
        "jenis",
        "updated_at", 
        "deleted_at" 
    ];
    
    protected $fillable = [
        'idsis',
        'jen',
        'tgl_mulai',
        'tgl_akhir',
        'ket',
        'dok',
        'sta',
    ];

    public function jenis(): BelongsTo
    {
        return $this->belongsTo(TizinJenis::class, 'jen', 'id');
    }

    

    public function siswa(): BelongsTo
    {
        return $this->belongsTo(Tsiswa::class, 'idsis', 'id');
    }

    public function documents(): MorphMany
    {
        $instance = (new Timagable())->setConnection('mai4');

        return $this->newMorphMany(
            $instance->newQuery(),
            $this,
            $instance->qualifyColumn('imagable_type'),
            $instance->qualifyColumn('imagable_id'),
            $this->getKeyName()
        );
    }
  
}
