This commit is contained in:
m.zargarov 2024-06-20 15:57:12 +04:00
parent 24b5683090
commit 2255a901be
4 changed files with 22 additions and 1 deletions

View File

@ -91,4 +91,11 @@ class StudentController extends Controller
return redirect()->route('students.index');
}
public function scores(StudentService $service): View
{
return view('students.scores', [
'scores' => $service->getScores(),
]);
}
}

View File

@ -39,7 +39,7 @@ class Student extends Model
public function lessons(): BelongsToMany
{
return $this->belongsToMany(Lesson::class);
return $this->belongsToMany(Lesson::class)->withPivot('score');
}
public function scopeFilter(Builder $query): void

View File

@ -5,7 +5,9 @@ namespace App\Services;
use App\Enums\ScoreEnum;
use App\Models\Student;
use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Auth;
class StudentService
{
@ -53,4 +55,14 @@ class StudentService
$model->user()->delete();
$model->delete();
}
public function getScores(): Collection
{
$student = Auth::user()->userable;
foreach ($student->lessons as $lesson) {
dd($lesson->pivot->score);
}
return $student->lessons;
}
}

View File

@ -42,6 +42,8 @@ Route::middleware('auth')->group(function () {
Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf');
Route::get('grades/{grade}/subjects/{subject}/journal', [GradeSubjectController::class, 'journal'])->name('grades.subjects.journal');
Route::get('student-scores', [StudentController::class, 'scores'])->name('student-scores');
});
require __DIR__.'/auth.php';