Teacher.php 886 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. use Illuminate\Database\Eloquent\Relations\HasMany;
  7. class Teacher extends Model
  8. {
  9. use HasFactory;
  10. protected $table = 'teachers';
  11. protected $primaryKey = 'teacher_id';
  12. public $incrementing = false;
  13. protected $keyType = 'int';
  14. protected $fillable = [
  15. 'teacher_id',
  16. 'user_id',
  17. 'name',
  18. 'subject',
  19. ];
  20. /**
  21. * 对应老师用户信息。
  22. */
  23. public function user(): BelongsTo
  24. {
  25. return $this->belongsTo(User::class, 'user_id', 'user_id');
  26. }
  27. /**
  28. * 老师下的学生。
  29. */
  30. public function students(): HasMany
  31. {
  32. return $this->hasMany(Student::class, 'teacher_id', 'teacher_id');
  33. }
  34. }