From 25d3463182ad9f5897d1b63d6f1747bfc66023c7 Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Fri, 17 May 2024 18:46:12 +0400 Subject: [PATCH] Added show scores + some fixes --- app/Enums/ScoreEnum.php | 14 ++++++ app/Http/Controllers/ScoreController.php | 19 +++++++- app/Models/Lesson.php | 2 +- app/Models/Student.php | 2 +- app/Providers/ModelServiceProvider.php | 9 ++++ resources/views/grade-lesson/show.blade.php | 2 +- resources/views/scores/show.blade.php | 53 +++++++++++++++++++++ resources/views/students/index.blade.php | 2 +- routes/web.php | 4 +- 9 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 app/Enums/ScoreEnum.php create mode 100644 resources/views/scores/show.blade.php diff --git a/app/Enums/ScoreEnum.php b/app/Enums/ScoreEnum.php new file mode 100644 index 0000000..8a4578b --- /dev/null +++ b/app/Enums/ScoreEnum.php @@ -0,0 +1,14 @@ + $this->service->getAll($lesson), + 'lesson' => $lesson, + 'scores' => ScoreEnum::cases(), + ]); + } } diff --git a/app/Models/Lesson.php b/app/Models/Lesson.php index d84a598..a52aad6 100644 --- a/app/Models/Lesson.php +++ b/app/Models/Lesson.php @@ -45,7 +45,7 @@ class Lesson extends Model public function students(): BelongsToMany { - return $this->belongsToMany(Student::class); + return $this->belongsToMany(Student::class)->withPivot('score'); } public function scopeFilter(Builder $query): void diff --git a/app/Models/Student.php b/app/Models/Student.php index dd09607..b7f93d0 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -39,7 +39,7 @@ class Student extends Model public function lessons(): BelongsToMany { - return $this->belongsToMany(Lesson::class)->withPivot('score'); + return $this->belongsToMany(Lesson::class); } public function scopeFilter(Builder $query): void diff --git a/app/Providers/ModelServiceProvider.php b/app/Providers/ModelServiceProvider.php index aea0c78..e2a8d11 100644 --- a/app/Providers/ModelServiceProvider.php +++ b/app/Providers/ModelServiceProvider.php @@ -6,6 +6,7 @@ use App\Http\Controllers\GradeController; use App\Http\Controllers\GradeSubjectController; use App\Http\Controllers\GradeTeacherController; use App\Http\Controllers\LessonController; +use App\Http\Controllers\ScoreController; use App\Http\Controllers\StudentController; use App\Http\Controllers\SubjectController; use App\Http\Controllers\SubjectTeacherController; @@ -14,6 +15,7 @@ use App\Services\GradeService; use App\Services\GradeSubjectService; use App\Services\GradeTeacherService; use App\Services\LessonService; +use App\Services\ScoreService; use App\Services\ServiceInterface; use App\Services\StudentService; use App\Services\SubjectService; @@ -75,6 +77,13 @@ class ModelServiceProvider extends ServiceProvider ->give(function () { return new LessonService(); }); + + + $this->app->when(ScoreController::class) + ->needs(ServiceInterface::class) + ->give(function () { + return new ScoreService(); + }); } /** diff --git a/resources/views/grade-lesson/show.blade.php b/resources/views/grade-lesson/show.blade.php index 722d92c..a645a72 100644 --- a/resources/views/grade-lesson/show.blade.php +++ b/resources/views/grade-lesson/show.blade.php @@ -20,7 +20,7 @@ diff --git a/resources/views/scores/show.blade.php b/resources/views/scores/show.blade.php new file mode 100644 index 0000000..c6f8afa --- /dev/null +++ b/resources/views/scores/show.blade.php @@ -0,0 +1,53 @@ +@extends('layouts.app') + +@section('content') +
+
+
+
+

{{ $lesson->name }}

+
+
+
+ @csrf + @method('PUT') + @if(count($students)) + + + + + + + @foreach ($students as $student) + + + + + @endforeach + +
ФИООценка
+
+

{{ $student->fio }}

+
+
+
+ +
+
+ @else +

Ученики остутствуют

+ @endif + +
+
+
+
+
+@endsection diff --git a/resources/views/students/index.blade.php b/resources/views/students/index.blade.php index 822b81a..a3b9cf2 100644 --- a/resources/views/students/index.blade.php +++ b/resources/views/students/index.blade.php @@ -31,7 +31,7 @@
- {{ $student->last_name }} {{ $student->name }} {{ $student->middle_name }} + {{ $student->fio }}
diff --git a/routes/web.php b/routes/web.php index c426a20..99f2059 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ use App\Http\Controllers\GradeController; use App\Http\Controllers\GradeSubjectController; use App\Http\Controllers\GradeTeacherController; use App\Http\Controllers\LessonController; +use App\Http\Controllers\ScoreController; use App\Http\Controllers\StudentController; use App\Http\Controllers\SubjectController; use App\Http\Controllers\SubjectTeacherController; @@ -25,4 +26,5 @@ Route::resources([ Route::resource('teachers.subjects', SubjectTeacherController::class)->except('index'); Route::resource('teachers.subjects.grades', GradeTeacherController::class)->except('index', 'show'); Route::resource('grades.subjects', GradeSubjectController::class)->except('index', 'show'); -Route::resource('lessons.students', ScoreController::class)->except('show'); +Route::get('lessons/{lesson}/scores', [ScoreController::class, 'show'])->name('lessons.scores.show'); +Route::put('lessons/{lesson}/scores', [ScoreController::class, 'update'])->name('lessons.scores.update');