refactor: update Eloquent models to use guarded attributes and consolidate relationship definitions
This commit is contained in:
parent
c460fec1f2
commit
0b8d4ef09b
@ -16,14 +16,7 @@ class Assignment extends Model implements HasMedia
|
|||||||
{
|
{
|
||||||
use HasFactory, InteractsWithMedia, SoftDeletes;
|
use HasFactory, InteractsWithMedia, SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'course_id',
|
|
||||||
'class_session_id',
|
|
||||||
'description',
|
|
||||||
'due_date',
|
|
||||||
'title',
|
|
||||||
'type',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
@ -48,16 +41,16 @@ public function assignmentTargets(): HasMany
|
|||||||
return $this->hasMany(AssignmentTarget::class);
|
return $this->hasMany(AssignmentTarget::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function course(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Course::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function classSession(): BelongsTo
|
public function classSession(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(ClassSession::class);
|
return $this->belongsTo(ClassSession::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function course(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Course::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function students(): BelongsToMany
|
public function students(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(
|
return $this->belongsToMany(
|
||||||
|
|||||||
@ -7,10 +7,7 @@
|
|||||||
|
|
||||||
class AssignmentPin extends Model
|
class AssignmentPin extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'assignment_id',
|
|
||||||
'student_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function assignment(): BelongsTo
|
public function assignment(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,13 +12,7 @@ class AssignmentSubmission extends Model implements HasMedia
|
|||||||
{
|
{
|
||||||
use HasFactory, InteractsWithMedia;
|
use HasFactory, InteractsWithMedia;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'assignment_id',
|
|
||||||
'notes',
|
|
||||||
'student_id',
|
|
||||||
'study_group_id',
|
|
||||||
'submitted_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -10,11 +10,7 @@ class AssignmentTarget extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'assignment_id',
|
|
||||||
'student_id',
|
|
||||||
'study_group_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function assignment(): BelongsTo
|
public function assignment(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class Attendance extends Model
|
class Attendance extends Model
|
||||||
{
|
{
|
||||||
@ -16,18 +17,18 @@ protected function casts(): array
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function student()
|
public function classSession(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Student::class);
|
return $this->belongsTo(ClassSession::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function courseSchedule()
|
public function courseSchedule(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(CourseSchedule::class);
|
return $this->belongsTo(CourseSchedule::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function classSession()
|
public function student(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(ClassSession::class);
|
return $this->belongsTo(Student::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,29 +12,16 @@ class ClassSession extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes;
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'course_id',
|
|
||||||
'session_number',
|
|
||||||
'date',
|
|
||||||
'start_time',
|
|
||||||
'end_time',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $casts = [
|
protected function casts(): array
|
||||||
'date' => 'date',
|
|
||||||
'session_number' => 'integer',
|
|
||||||
'start_time' => 'datetime',
|
|
||||||
'end_time' => 'datetime',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function course(): BelongsTo
|
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Course::class);
|
return [
|
||||||
}
|
'date' => 'date',
|
||||||
|
'session_number' => 'integer',
|
||||||
public function materials(): HasMany
|
'start_time' => 'datetime',
|
||||||
{
|
'end_time' => 'datetime',
|
||||||
return $this->hasMany(Material::class);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assignments(): HasMany
|
public function assignments(): HasMany
|
||||||
@ -46,4 +33,14 @@ public function attendances(): HasMany
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Attendance::class);
|
return $this->hasMany(Attendance::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function course(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Course::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function materials(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Material::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,21 @@ protected static function booted()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assignments(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Assignment::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function classSessions(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(ClassSession::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function courseSchedules(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(CourseSchedule::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function materials(): HasMany
|
public function materials(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Material::class);
|
return $this->hasMany(Material::class);
|
||||||
@ -30,14 +45,4 @@ public function studyGroups(): BelongsToMany
|
|||||||
{
|
{
|
||||||
return $this->belongsToMany(StudyGroup::class, 'study_group_courses');
|
return $this->belongsToMany(StudyGroup::class, 'study_group_courses');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function courseSchedules(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(CourseSchedule::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function classSessions(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(ClassSession::class);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
@ -37,13 +38,53 @@ protected function female(Builder $query): void
|
|||||||
$query->where('sex', Sex::Female);
|
$query->where('sex', Sex::Female);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function user(): BelongsTo
|
public function assignmentPins(): HasMany
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->hasMany(AssignmentPin::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignments(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(
|
||||||
|
Assignment::class,
|
||||||
|
'assignment_targets',
|
||||||
|
'student_id',
|
||||||
|
'assignment_id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignmentSubmissions(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(AssignmentSubmission::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignmentTargets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(AssignmentTarget::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function attendances(): HasMany
|
public function attendances(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(Attendance::class);
|
return $this->hasMany(Attendance::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ledStudyGroups(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(StudyGroup::class, 'leader_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function studyGroupMembers(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(StudyGroupMember::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function studyGroups(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(StudyGroup::class, 'study_group_members');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,16 +13,33 @@ class StudyGroup extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes;
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'leader_id',
|
|
||||||
'name',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function isLeader(Student $student): bool
|
public function isLeader(Student $student): bool
|
||||||
{
|
{
|
||||||
return $this->leader_id === $student->id;
|
return $this->leader_id === $student->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function assignmentSubmissions(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(AssignmentSubmission::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignmentTargets(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(AssignmentTarget::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assignments(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(
|
||||||
|
Assignment::class,
|
||||||
|
'assignment_targets',
|
||||||
|
'study_group_id',
|
||||||
|
'assignment_id'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function courses(): BelongsToMany
|
public function courses(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Course::class, 'study_group_courses');
|
return $this->belongsToMany(Course::class, 'study_group_courses');
|
||||||
|
|||||||
@ -10,10 +10,7 @@ class StudyGroupMember extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $guarded = ['id'];
|
||||||
'student_id',
|
|
||||||
'study_group_id',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function student(): BelongsTo
|
public function student(): BelongsTo
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user