blob: 6c46e3521939ecff210e2aa4564925498cc49334 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class Student extends Model
{
use HasFactory;
protected $table = 'students';
protected $fillable = [
'name',
'last_name',
'age',
'group_id',
'sub_group_id',
'points',
'enrollment_date',
];
protected $casts = [
'enrollment_date' => 'date',
];
/**
* Get the group this student belongs to.
*/
public function group(): BelongsTo
{
return $this->belongsTo(Group::class);
}
/**
* Get the sub-group this student belongs to.
*/
public function subGroup(): BelongsTo
{
return $this->belongsTo(SubGroup::class);
}
/**
* Get the lessons this student attends.
*/
public function lessons(): BelongsToMany
{
return $this->belongsToMany(Lesson::class, 'lesson_student')
->withPivot('attendance', 'score')
->withTimestamps();
}
/**
* Get the activities this student participates in.
*/
public function activities(): BelongsToMany
{
return $this->belongsToMany(Activity::class, 'activity_student')
->withPivot('score', 'notes')
->withTimestamps();
}
}
|