Task-10 (Journal) #11
@ -118,4 +118,11 @@ class StudentController extends Controller
|
|||||||
|
|
||||||
return redirect()->route('students.index');
|
return redirect()->route('students.index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scores(StudentService $service): View
|
||||||
|
{
|
||||||
|
return view('students.scores', [
|
||||||
|
'scores' => $service->getScores(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ class Student extends Model
|
|||||||
|
|
||||||
public function lessons(): BelongsToMany
|
public function lessons(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Lesson::class);
|
return $this->belongsToMany(Lesson::class)->withPivot('score');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeFilter(Builder $query): void
|
public function scopeFilter(Builder $query): void
|
||||||
|
@ -5,7 +5,9 @@ namespace App\Services;
|
|||||||
use App\Enums\ScoreEnum;
|
use App\Enums\ScoreEnum;
|
||||||
use App\Models\Student;
|
use App\Models\Student;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class StudentService
|
class StudentService
|
||||||
{
|
{
|
||||||
@ -53,4 +55,14 @@ class StudentService
|
|||||||
$model->user()->delete();
|
$model->user()->delete();
|
||||||
$model->delete();
|
$model->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getScores(): Collection
|
||||||
|
{
|
||||||
|
$student = Auth::user()->userable;
|
||||||
|
foreach ($student->lessons as $lesson) {
|
||||||
|
dd($lesson->pivot->score);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $student->lessons;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,8 @@ Route::middleware('auth')->group(function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf');
|
Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf');
|
||||||
|
|
||||||
|
Route::get('student-scores', [StudentController::class, 'scores'])->name('student-scores');
|
||||||
});
|
});
|
||||||
|
|
||||||
require __DIR__.'/auth.php';
|
require __DIR__.'/auth.php';
|
||||||
|
Loading…
Reference in New Issue
Block a user