task-5 (Lessons and Scores) #5

Merged
klllst merged 16 commits from feature/task-5 into develop 2024-05-27 18:42:11 +04:00
4 changed files with 35 additions and 2 deletions
Showing only changes of commit 619254a204 - Show all commits

View File

@ -33,6 +33,7 @@ class LessonController extends Controller
return view('grade-lesson.index', [
'lessons' => $this->service->getAll($grade),
'grade' => $grade,
'subjects' => $grade->subjects,
]);
}

View File

@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -40,4 +41,13 @@ class Lesson extends Model
{
return $this->belongsTo(Subject::class);
}
public function scopeFilter(Builder $query): void
{
$subject_id = request('subject_id');
$query->when($subject_id, function (Builder $query, $subject_id) {
$query->where('subject_id', $subject_id);
});
}
}

View File

@ -12,7 +12,7 @@ class LessonService implements ServiceInterface
public function getAll(?Grade $grade = null): Collection
{
return $grade->lessons;
return $grade->lessons()->filter()->get();
}
public function getGrades(): Collection

View File

@ -1,4 +1,4 @@
@extends('layouts.app')
`@extends('layouts.app')
@section('content')
<div class="container col-md-5">
@ -9,6 +9,27 @@
<a href="{{ route('grades.lessons.create', $grade) }}" class="btn btn-success">Добавить</a>
</div>
</div>
<div class="card mt-4">
<div class="card-header">{{__('Фильтрация')}}</div>
<div class="card-body">
<form action="{{ route('grades.lessons.index', $grade) }}" method="GET">
<div class="mb-3">
<label for="subject_id" class="form-label">Предмет:</label>
<select id="subject_id" name="subject_id" class="form-select" required>
<option value="">Выберите предмет</option>
@foreach($subjects as $subject)
<option value="{{ $subject->id }}"> {{ $subject->id == request('subject_id') ? 'selected' : ''}}
{{ $subject->name }}
</option>
@endforeach
</select>
</div>
<div>
<button type="submit" class="btn btn-primary">Фильтр</button>
</div>
</form>
</div>
</div>
@if(count($lessons))
@foreach($lessons as $lesson)
<a href="{{ route('grades.lessons.show', [$grade, $lesson]) }}" class="text-decoration-none">
@ -33,3 +54,4 @@
</div>
@endsection
`