30 lines
716 B
PHP
30 lines
716 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Subject extends Model
|
|
{
|
|
protected $table = 'subjects';
|
|
|
|
// Mengizinkan pengisian massal untuk kolom id dan name
|
|
protected $fillable = [
|
|
'id',
|
|
'name'
|
|
];
|
|
|
|
// Relasi balik ke QuestionBank (Opsional, tapi baik untuk ke depannya)
|
|
public function questions()
|
|
{
|
|
return $this->hasMany(QuestionBank::class, 'subject_id');
|
|
}
|
|
|
|
public function users() // atau employees()
|
|
{
|
|
// Paksa pencarian menggunakan 'user_id'
|
|
return $this->belongsToMany(User::class, 'employee_subject', 'subject_id', 'user_id')
|
|
->withPivot('status')
|
|
->withTimestamps();
|
|
}
|
|
} |