KnowledgePointMasterySnapshot.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use App\Models\Student;
  7. class KnowledgePointMasterySnapshot extends Model
  8. {
  9. use HasFactory;
  10. protected $table = 'knowledge_point_mastery_snapshots';
  11. protected $primaryKey = 'snapshot_id';
  12. public $incrementing = false;
  13. protected $keyType = 'string';
  14. protected $fillable = [
  15. 'snapshot_id',
  16. 'student_id',
  17. 'paper_id',
  18. 'answer_record_id',
  19. 'analysis_id',
  20. 'mastery_data',
  21. 'current_mastery',
  22. 'overall_mastery',
  23. 'weak_knowledge_points_count',
  24. 'strong_knowledge_points_count',
  25. 'snapshot_time',
  26. 'created_at',
  27. 'updated_at',
  28. ];
  29. protected $casts = [
  30. 'mastery_data' => 'array',
  31. 'current_mastery' => 'array',
  32. 'snapshot_time' => 'datetime',
  33. 'created_at' => 'datetime',
  34. 'updated_at' => 'datetime',
  35. 'overall_mastery' => 'decimal:4',
  36. ];
  37. public function student(): BelongsTo
  38. {
  39. return $this->belongsTo(Student::class, 'student_id', 'student_id');
  40. }
  41. public function scopeForStudent($query, string $studentId)
  42. {
  43. return $query->where('student_id', $studentId);
  44. }
  45. }