<?php

namespace App\Models;

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

class Mapel extends Model
{
    use HasFactory;

    protected $table = 'mapels';  
    protected $primaryKey = 'id_mapel';
    public $incrementing = true;
    protected $keyType = 'int';

    protected $fillable = [
        'nama_mapel',
    ];

    // Relasi ke Mengajar (mapel diajar di kelas mana aja lewat guru)
    public function mengajars()
    {
        return $this->hasMany(Mengajar::class, 'id_mapel', 'id_mapel');
    }

    // Relasi many-to-many ke Kelas (lewat mengajars)
    public function kelas()
    {
        return $this->belongsToMany(Kelas::class, 'mengajars', 'id_mapel', 'id_kelas');
    }
}