aboutsummaryrefslogtreecommitdiffstats
path: root/app/Models/Lesson.php
blob: a88f4cb0bbeac6d7f49febbf72b10ad1e337a3d4 (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
<?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\BelongsToMany;

class Lesson extends Model
{
    use HasFactory;

    protected $fillable = [
        'topic',
        'description',
        'teacher_id',
        'group_id',
        'scheduled_at',
        'duration_minutes',
    ];

    protected $casts = [
        'scheduled_at' => 'datetime',
    ];

    /**
     * Get the teacher that teaches this lesson.
     */
    public function teacher(): BelongsTo
    {
        return $this->belongsTo(Teacher::class);
    }

    /**
     * Get the group for this lesson.
     */
    public function group(): BelongsTo
    {
        return $this->belongsTo(Group::class);
    }

    /**
     * Get the students attending this lesson.
     */
    public function students(): BelongsToMany
    {
        return $this->belongsToMany(Student::class, 'lesson_student')
            ->withPivot('attendance', 'score')
            ->withTimestamps();
    }
}