task-5 (Lessons and Scores) #5

Merged
klllst merged 16 commits from feature/task-5 into develop 2024-05-27 18:42:11 +04:00
3 changed files with 13 additions and 1 deletions
Showing only changes of commit 7a80e52d3c - Show all commits

View File

@ -4,6 +4,7 @@ namespace App\Models;
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\HasMany;
class Lesson extends Model class Lesson extends Model
{ {
@ -14,4 +15,9 @@ class Lesson extends Model
'type', 'type',
'lesson_date', 'lesson_date',
]; ];
public function scores(): HasMany
{
return $this->hasMany(Score::class);
}
} }

View File

@ -3,9 +3,15 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot; use Illuminate\Database\Eloquent\Relations\Pivot;
class Score extends Pivot class Score extends Pivot
{ {
use HasFactory; use HasFactory;
public function lesson(): BelongsTo
{
return $this->belongsTo(Lesson::class);
}
} }

View File

@ -34,7 +34,7 @@ class Student extends Model
public function subjects(): BelongsToMany public function subjects(): BelongsToMany
{ {
return $this->belongsToMany(Subject::class)->using(Score::class); return $this->belongsToMany(Subject::class)->withPivot('mark')->using(Score::class);
} }
public function scopeFilter(Builder $query): void public function scopeFilter(Builder $query): void