| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class Teacher extends Model
- {
- use HasFactory;
- protected $table = 'teachers';
- protected $primaryKey = 'teacher_id';
- public $incrementing = false;
- protected $keyType = 'int';
- public $timestamps = false; // 禁用时间戳,因为数据库表没有 updated_at 字段
- protected $fillable = [
- 'teacher_id',
- 'user_id',
- 'name',
- 'subject',
- ];
- /**
- * 对应老师用户信息。
- */
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class, 'user_id', 'user_id');
- }
- /**
- * 老师下的学生。
- */
- public function students(): HasMany
- {
- return $this->hasMany(Student::class, 'teacher_id', 'teacher_id');
- }
- }
|