prod #7

Merged
klllst merged 40 commits from feature/task-7 into master 2024-06-16 12:25:52 +04:00
5 changed files with 17 additions and 51 deletions
Showing only changes of commit 2de4f3ca82 - Show all commits

View File

@ -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');

View File

@ -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);
}
}

View File

@ -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

View File

@ -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');
});
}
};

View File

@ -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');
}
};