Detailing fungsi semua modul dari bugs error
This commit is contained in:
+14
-6
@@ -2,20 +2,28 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Exam extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'old_id',
|
||||
'title',
|
||||
'duration',
|
||||
'passing_percentage'
|
||||
'description',
|
||||
'training_type',
|
||||
'subject_id',
|
||||
'duration_minutes',
|
||||
'passing_grade',
|
||||
'max_retakes',
|
||||
'is_random_order',
|
||||
'is_active'
|
||||
];
|
||||
|
||||
public function results(): HasMany
|
||||
// Relasi: Setiap Ujian pasti milik satu Materi (Subject)
|
||||
public function subject()
|
||||
{
|
||||
return $this->hasMany(ExamResult::class);
|
||||
return $this->belongsTo(Subject::class);
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,10 @@ class QuestionBank extends Model
|
||||
protected $table = 'question_banks';
|
||||
|
||||
protected $fillable = [
|
||||
// Atribut Soal dari desain Anda
|
||||
'old_id',
|
||||
'subject_id',
|
||||
'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',
|
||||
'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'
|
||||
];
|
||||
|
||||
|
||||
@@ -19,4 +19,12 @@ class Subject extends Model
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
+10
-2
@@ -73,10 +73,18 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Position::class, 'position_id');
|
||||
}
|
||||
|
||||
public function subjects()
|
||||
{
|
||||
// Parameter ke-3 'user_id' akan memaksa Laravel mengabaikan pencarian 'employee_id'
|
||||
return $this->belongsToMany(\App\Models\Subject::class, 'employee_subject', 'user_id', 'subject_id')
|
||||
->withPivot('status')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function trainings()
|
||||
{
|
||||
// Ubah 'user_id' menjadi 'employee_id' agar sesuai dengan database Anda saat ini
|
||||
return $this->belongsToMany(Subject::class, 'employee_subject', 'employee_id', 'subject_id')
|
||||
// Karena ini Model User, foreign key-nya harus 'user_id'
|
||||
return $this->belongsToMany(Subject::class, 'employee_subject', 'user_id', 'subject_id')
|
||||
->withPivot('status')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user