Student.php 890 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. class Student extends Model
  7. {
  8. use HasFactory;
  9. protected $table = 'students';
  10. protected $primaryKey = 'student_id';
  11. public $incrementing = false;
  12. protected $keyType = 'int';
  13. protected $fillable = [
  14. 'student_id',
  15. 'name',
  16. 'grade',
  17. 'class_name',
  18. 'teacher_id',
  19. 'remark',
  20. ];
  21. protected $casts = [
  22. 'created_at' => 'datetime',
  23. 'updated_at' => 'datetime',
  24. ];
  25. public function teacher(): BelongsTo
  26. {
  27. return $this->belongsTo(Teacher::class, 'teacher_id', 'teacher_id');
  28. }
  29. public function user(): BelongsTo
  30. {
  31. return $this->belongsTo(User::class, 'student_id', 'user_id');
  32. }
  33. }