55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class QuestionBank extends Model
|
|
{
|
|
// Opsional, tapi sangat disarankan agar Laravel tidak salah menebak nama tabel
|
|
protected $table = 'question_banks';
|
|
|
|
protected $fillable = [
|
|
'subject_id', 'department_id', 'position_id', 'question_type',
|
|
'question_level', 'question_text', 'option_a', 'option_b',
|
|
'option_c', 'option_d', 'option_e', 'correct_answer',
|
|
'essay_keywords', 'score_weight', 'passing_grade', 'duration',
|
|
'created_by'
|
|
];
|
|
|
|
protected $casts = [
|
|
'correct_answer' => 'array', // Otomatis ubah JSON di database jadi Array di PHP
|
|
];
|
|
|
|
public function subject()
|
|
{
|
|
return $this->belongsTo(Subject::class, 'subject_id');
|
|
}
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| RELASI DATABASE (Diperlukan agar Filter Dropdown & Tabel berfungsi)
|
|
|--------------------------------------------------------------------------
|
|
*/
|
|
|
|
public function department()
|
|
{
|
|
return $this->belongsTo(Department::class, 'department_id');
|
|
}
|
|
|
|
public function position()
|
|
{
|
|
return $this->belongsTo(Position::class, 'position_id');
|
|
}
|
|
|
|
public function matrix()
|
|
{
|
|
return $this->belongsTo(TrainingMatrix::class, 'training_matrix_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
// Merujuk ke tabel users untuk mengetahui siapa staff/admin yang buat soal
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
} |