100 lines
2.1 KiB
PHP
100 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Teachers;
|
|
|
|
use App\Models\BaseModel;
|
|
use App\Models\Schools\School;
|
|
use App\Models\Schools\SchoolClass;
|
|
use App\Models\User;
|
|
|
|
/**
|
|
* 老师班级关联模型
|
|
* @package App\Models\Teachers
|
|
* @property int $id 主键ID
|
|
* @property int $teacher_id 老师ID
|
|
* @property int $school_id 学校ID
|
|
* @property int $grade_id 年级ID
|
|
* @property int $class_id 班级ID
|
|
* @property int $headman 是否班主任(1是0否)
|
|
* @property \Carbon\Carbon $created_at 创建时间
|
|
* @property \Carbon\Carbon $updated_at 更新时间
|
|
* @property \Carbon\Carbon|null $deleted_at 删除时间
|
|
* @property int $tenant_id 租户ID
|
|
*/
|
|
class TeacherClass extends BaseModel
|
|
{
|
|
protected $table = 'teacher_class';
|
|
|
|
protected $fillable = [
|
|
'teacher_id',
|
|
'school_id',
|
|
'grade_id',
|
|
'class_id',
|
|
'headman',
|
|
];
|
|
|
|
protected $casts = [
|
|
'teacher_id' => 'integer',
|
|
'school_id' => 'integer',
|
|
'grade_id' => 'integer',
|
|
'class_id' => 'integer',
|
|
'headman' => 'integer',
|
|
];
|
|
|
|
/**
|
|
* 关联老师(系统用户)
|
|
*/
|
|
public function teacher()
|
|
{
|
|
return $this->belongsTo(User::class, 'teacher_id');
|
|
}
|
|
|
|
/**
|
|
* 关联学校
|
|
*/
|
|
public function school()
|
|
{
|
|
return $this->belongsTo(School::class, 'school_id');
|
|
}
|
|
|
|
/**
|
|
* 关联班级
|
|
*/
|
|
public function schoolClass()
|
|
{
|
|
return $this->belongsTo(SchoolClass::class, 'class_id');
|
|
}
|
|
|
|
/**
|
|
* 根据老师ID查询
|
|
*/
|
|
public function scopeByTeacher($query, $teacherId)
|
|
{
|
|
return $query->where('teacher_id', $teacherId);
|
|
}
|
|
|
|
/**
|
|
* 根据学校ID查询
|
|
*/
|
|
public function scopeBySchool($query, $schoolId)
|
|
{
|
|
return $query->where('school_id', $schoolId);
|
|
}
|
|
|
|
/**
|
|
* 根据班级ID查询
|
|
*/
|
|
public function scopeByClass($query, $classId)
|
|
{
|
|
return $query->where('class_id', $classId);
|
|
}
|
|
|
|
/**
|
|
* 查询班主任
|
|
*/
|
|
public function scopeHeadman($query)
|
|
{
|
|
return $query->where('headman', 1);
|
|
}
|
|
}
|