task-5 (Lessons and Scores) #5
@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Lesson extends Model
|
||||
{
|
||||
@ -14,4 +15,9 @@ class Lesson extends Model
|
||||
'type',
|
||||
'lesson_date',
|
||||
];
|
||||
|
||||
public function scores(): HasMany
|
||||
{
|
||||
return $this->hasMany(Score::class);
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,15 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
class Score extends Pivot
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public function lesson(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Lesson::class);
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ class Student extends Model
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user