63 lines
1.1 KiB
PHP
63 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Materi extends Model
|
|
{
|
|
protected $table = 'materi';
|
|
|
|
protected $fillable = [
|
|
'guru_id',
|
|
'mapel_id',
|
|
'parent_id',
|
|
'judul',
|
|
'isi',
|
|
'file',
|
|
];
|
|
|
|
public function mapel()
|
|
{
|
|
return $this->belongsTo(Mapel::class);
|
|
}
|
|
|
|
public function guru()
|
|
{
|
|
return $this->belongsTo(Guru::class);
|
|
}
|
|
|
|
public function parent()
|
|
{
|
|
return $this->belongsTo(Materi::class, 'parent_id');
|
|
}
|
|
|
|
public function children()
|
|
{
|
|
return $this->hasMany(Materi::class, 'parent_id');
|
|
}
|
|
|
|
public function tugas()
|
|
{
|
|
return $this->hasMany(Tugas::class);
|
|
}
|
|
public function forumDiskusi()
|
|
{
|
|
return $this->hasMany(\App\Models\ForumDiskusi::class);
|
|
}
|
|
public function guruMapel()
|
|
{
|
|
return $this->belongsTo(\App\Models\GuruMapel::class);
|
|
}
|
|
// app/Models/Materi.php
|
|
|
|
public function kelas()
|
|
{
|
|
return $this->belongsToMany(Kelas::class, 'kelas_materi', 'materi_id', 'kelas_id')
|
|
->withPivot('tanggal_terbit')
|
|
->withTimestamps();
|
|
}
|
|
|
|
|
|
}
|