prod #7
@ -6,6 +6,7 @@ use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Lesson extends Model
|
||||
@ -42,6 +43,11 @@ class Lesson extends Model
|
||||
return $this->belongsTo(Subject::class);
|
||||
}
|
||||
|
||||
public function students(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Student::class);
|
||||
}
|
||||
|
||||
public function scopeFilter(Builder $query): void
|
||||
{
|
||||
$subject_id = request('subject_id');
|
||||
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
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,12 @@ class Student extends Model
|
||||
|
||||
public function subjects(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Subject::class)->withPivot('mark')->using(Score::class);
|
||||
return $this->belongsToMany(Subject::class);
|
||||
}
|
||||
|
||||
public function lessons(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Lesson::class)->withPivot('score');
|
||||
}
|
||||
|
||||
public function scopeFilter(Builder $query): void
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('student_subject', function (Blueprint $table) {
|
||||
$table->foreignId('lesson_id')->nullable()->constrained('lessons')->onDelete('cascade');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('student_subject', function (Blueprint $table) {
|
||||
$table->dropColumn('lesson_id');
|
||||
});
|
||||
}
|
||||
};
|
@ -11,11 +11,11 @@ return new class extends Migration
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('student_subject', function (Blueprint $table) {
|
||||
Schema::create('lesson_student', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('student_id')->constrained('students')->onDelete('cascade');
|
||||
$table->foreignId('subject_id')->constrained('subjects')->onDelete('cascade');
|
||||
$table->unsignedInteger('mark');
|
||||
$table->foreignId('lesson_id')->constrained('lessons')->onDelete('cascade');
|
||||
$table->foreignId('student_id')->constrained('lessons')->onDelete('cascade');
|
||||
$table->unsignedInteger('score');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
@ -25,6 +25,6 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('student_subject');
|
||||
Schema::dropIfExists('lesson_student');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user