<?php

namespace App\Models;

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

class Kelas extends Model
{
    use HasFactory;

    protected $table = 'kelas'; 
    protected $primaryKey = 'id_kelas';
    public $incrementing = true;
    protected $keyType = 'int';

    protected $fillable = [
        'id_kelas',
        'nama_kelas',
        'tingkat',
    ];

    // Relasi ke Siswa
    public function siswa()
    {
        return $this->hasMany(Siswa::class, 'id_kelas', 'id_kelas');
    }

    // Relasi ke Mengajar
    public function mengajars()
    {
        return $this->hasMany(Mengajar::class, 'id_kelas', 'id_kelas');
    }

    public function mapels()
    {
    return $this->belongsToMany(
        Mapel::class,
        'mengajars',
        'id_kelas',
        'id_mapel'
    );
    }

}