43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class PaketMapel extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'paket_mapel';
|
|
|
|
protected $fillable = ['nama_paket', 'deskripsi', 'kuota'];
|
|
|
|
// Relasi ke angket siswa (model AngketSiswa)
|
|
public function angketSiswa()
|
|
{
|
|
return $this->hasMany(AngketSiswa::class);
|
|
}
|
|
|
|
// Relasi many-to-many ke siswa lewat tabel angket_siswa sebagai pivot
|
|
public function siswas()
|
|
{
|
|
return $this->belongsToMany(
|
|
Siswa::class,
|
|
'angket_siswa', // tabel pivot
|
|
'paket_mapel_id', // foreign key di pivot yang mengarah ke paket_mapel
|
|
'siswa_id' // foreign key di pivot yang mengarah ke siswa
|
|
);
|
|
}
|
|
|
|
public function mapels()
|
|
{
|
|
return $this->belongsToMany(Mapel::class, 'paket_mapel_detail');
|
|
}
|
|
|
|
public function peringkat()
|
|
{
|
|
return $this->hasMany(PeringkatPaketMapel::class);
|
|
}
|
|
}
|