65 lines
1.7 KiB
PHP
65 lines
1.7 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 = [
|
|
// Atribut Soal dari desain Anda
|
|
'old_id',
|
|
'subject',
|
|
'question_type',
|
|
'question_level',
|
|
'passing_grade',
|
|
'duration',
|
|
'question_text',
|
|
'option_a',
|
|
'option_b',
|
|
'option_c',
|
|
'option_d',
|
|
'option_e',
|
|
'correct_answer',
|
|
|
|
// PENTING: Atribut Relasi yang dibutuhkan form Create/Edit & Filter Index
|
|
'department_id',
|
|
'position_id',
|
|
'training_matrix_id',
|
|
'created_by'
|
|
];
|
|
|
|
protected $casts = [
|
|
'correct_answer' => 'array', // Otomatis ubah JSON di database jadi Array di PHP
|
|
];
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| 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');
|
|
}
|
|
} |