Added lesson's views

This commit is contained in:
m.zargarov 2024-05-08 16:55:32 +04:00
parent d6778d1455
commit 6ad697924a
12 changed files with 195 additions and 21 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\Enums\TypeLesson;
use App\Http\Requests\LessonPostRequest;
use App\Models\Grade;
use App\Models\Lesson;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
@ -17,54 +18,67 @@ class LessonController extends Controller
){
}
public function gradeList(): View
{
return view('grade-lesson.grades-list', [
'grades' => $this->service->getGrades(),
]);
}
/**
* Display a listing of the resource.
*/
public function index(): View
public function index(Grade $grade): View
{
return view('lessons.index', [
'lessons' => $this->service->getAll(),
return view('grade-lesson.index', [
'lessons' => $this->service->getAll($grade),
'grade' => $grade,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
public function create(Grade $grade): View
{
return view('lessons.create', [
return view('grade-lesson.create', [
'types' => TypeLesson::cases(),
'grade' => $grade,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(LessonPostRequest $request): RedirectResponse
public function store(LessonPostRequest $request, Grade $grade): RedirectResponse
{
return redirect()->route(
'lessons.show',
'grades.lessons.show', [
$grade,
$this->service->create($request->validated())
]
);
}
/**
* Display the specified resource.
*/
public function show(Lesson $lesson): View
public function show(Grade $grade, Lesson $lesson): View
{
return view('lessons.show', [
return view('grade-lesson.show', [
'lesson' => $lesson,
'grade' => $grade,
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Lesson $lesson): View
public function edit(Grade $grade, Lesson $lesson): View
{
return view('lessons.edit', [
return view('grade-lesson.edit', [
'lesson' => $lesson,
'grade' => $grade,
'types' => TypeLesson::cases(),
]);
}
@ -72,21 +86,23 @@ class LessonController extends Controller
/**
* Update the specified resource in storage.
*/
public function update(LessonPostRequest $request, Lesson $lesson): RedirectResponse
public function update(LessonPostRequest $request, Grade $grade, Lesson $lesson): RedirectResponse
{
return redirect()->route(
'lessons.show',
'grades.lessons.show',[
$grade,
$this->service->update($lesson, $request->validated())
]
);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Lesson $lesson): RedirectResponse
public function destroy(Grade $grade, Lesson $lesson): RedirectResponse
{
$this->service->delete($lesson);
return redirect()->route('lessons.index');
return redirect()->route('grades.lessons.index', $grade);
}
}

View File

@ -27,6 +27,7 @@ class LessonPostRequest extends FormRequest
'name' => 'required|string|max:255',
'type' => ['required', Rule::in(TypeLesson::cases())],
'lesson_date' => 'required|date',
'description' => 'nullable|string|max:250',
'grade_id' => 'required|exists:grades,id',
'teacher_id' => 'required|exists:teachers,id',
'subject_id' => 'required|exists:subjects,id',

View File

@ -2,6 +2,7 @@
namespace App\Services;
use App\Models\Grade;
use App\Models\Lesson;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
@ -9,9 +10,14 @@ use Illuminate\Database\Eloquent\Model;
class LessonService implements ServiceInterface
{
public function getAll(): Collection
public function getAll(?Grade $grade = null): Collection
{
return Lesson::all();
return $grade->lessons;
}
public function getGrades(): Collection
{
return Grade::all();
}
public function create(array $data): Lesson

View File

@ -0,0 +1,5 @@
@extends('layouts.app')
@section('content')
@include('grade-lesson.form', ['route' => route('grades.lessons.store', $grade), 'method' => 'POST'])
@endsection

View File

@ -0,0 +1,5 @@
@extends('layouts.app')
@section('content')
@include('grade-lesson.form', ['route' => route('grades.lessons.update', [$grade, $lesson]), 'method' => 'PUT'])
@endsection

View File

@ -0,0 +1,51 @@
<div class="container col-md-5">
<div class="row justify-content-center">
<div class="card mt-4">
<div class="card-body">
<form action="{{ $route }}" method="POST">
@csrf
@method($method)
<div class="mb-3">
<label for="name" class="form-label">Тема:</label>
<input type="text" id="name" name="name" class="form-control" value="{{ isset($lesson) ? $lesson->name : old('name') }}" required>
</div>
<div class="mb-3">
<label for="type" class="form-label">Тип работы:</label>
<select id="type" name="type" class="form-select" required>
<option value="">Выберите тип деятельности</option>
@foreach($types as $type)
<option value="{{ $type }}" {{ isset($lesson) && $lesson->type == $type ? 'selected' : old('type') }}>
{{ $type }}
</option>
@endforeach
</select>
</div>
<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($grade->subjects as $subject)
<option value="{{ $subject->id }}" {{ isset($lesson) && $lesson->subject_id == $subject->id ? 'selected' : old('subject_id') }}>
{{ $subject->name }}
</option>
@endforeach
</select>
</div>
<div class="mb-3">
<label for="description" class="form-label">Описание(макс. 250 символов):</label>
<textarea class="form-control" id="description" name="description" rows="5" >{{ isset($lesson) ? $lesson->description : old('description') }}</textarea>
</div>
<div class="mb-3">
<label for="lesson_date" class="form-label">Дата рождения:</label>
<input type="date" id="lesson_date" name="lesson_date" class="form-control" value="{{ isset($lesson) ? $lesson->lesson_date : old('lesson_date') }}" required>
</div>
<input type="hidden" name="grade_id" value="{{ $grade->id }}">
<input type="hidden" name="teacher_id" value="{{ 1 }}"> {{-- заглушка --}}
<div>
<button type="submit" class="btn btn-success">Подтвердить</button>
</div>
</form>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,22 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-4">
<div class="row justify-content-center">
<div class="card mt-4">
<div class="card-header">{{__('Классы')}}</div>
<div class="card-body">
@if (count($grades))
<div class="list-group">
@foreach ($grades as $grade)
<a href="{{ route('grades.lessons.index', $grade) }}" class="list-group-item list-group-item-action d-flex justify-content-center">{{ $grade->name }}</a>
@endforeach
</div>
@else
<p>Классы отсутствуют</p>
@endif
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,35 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-5">
<div class="row justify-content-center">
<div class="card mt-4">
<div class="card-header">{{__('Создание занятия')}}</div>
<div class="card-body">
<a href="{{ route('grades.lessons.create', $grade) }}" class="btn btn-success">Добавить</a>
</div>
</div>
@if(count($lessons))
@foreach($lessons as $lesson)
<a href="{{ route('grades.lessons.show', [$grade, $lesson]) }}" class="text-decoration-none">
<div class="card mt-4">
<div class="card-header"><strong>{{$lesson->subject->name}}</strong></div>
<div class="card-header">{{$lesson->type}}</div>
<div class="card-body">
{{ $lesson->name }}
</div>
<div class="card-footer">
<form action="{{ route('grades.lessons.destroy', [$grade, $lesson]) }}" method="POST" style="display: inline-block;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</div>
</div>
</a>
@endforeach
@endif
</div>
</div>
@endsection

View File

@ -0,0 +1,30 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-6">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">{{ $lesson->type }}</div>
<div class="card-body">
<div class="mb-3">
<h5><strong>Тема: </strong>{{ $lesson->name }}</h5>
</div>
<div class="mb-3">
<h5><strong>Предмет: </strong>{{ $lesson->subject->name }}</h5>
</div>
<div class="mb-3">
<h5><strong>Дата: </strong>{{ $lesson->lesson_date }}</h5>
</div>
<div class="mb-3">
<h5><strong>Описание: </strong>{{ $lesson->description }}</h5>
</div>
</div>
<div class="card-footer">
<a href="{{ route('grades.lessons.edit', [$grade, $lesson]) }}" class="btn btn-primary">Редактировать</a>
</div>
</div>
</div>
</div>
@endsection

View File

@ -3,6 +3,7 @@
<ul class="nav justify-content-center pb-3 mb-3">
<li class="nav-item"><a href="{{ route('grades.index') }}" class="nav-link px-2 text-muted">Классы</a></li>
<li class="nav-item"><a href="{{ route('subjects.index') }}" class="nav-link px-2 text-muted">Предметы</a></li>
<li class="nav-item"><a href="{{ route('grades.lessons.grades-list') }}" class="nav-link px-2 text-muted">Занятия</a></li>
<li class="nav-item"><a href="{{ route('students.index') }}" class="nav-link px-2 text-muted">Студенты</a></li>
<li class="nav-item"><a href="{{ route('teachers.index') }}" class="nav-link px-2 text-muted">Учителя</a></li>
</ul>

View File

@ -2,7 +2,8 @@
<header class="d-flex justify-content-center py-3">
<ul class="nav nav-pills">
<li class="nav-item"><a href="{{ route('grades.index') }}" class="nav-link @if(request()->is('grades*')) active @endif" aria-current="page">Классы</a></li>
<li class="nav-item"><a href="{{ route('subjects.index') }}" class="nav-link @if(request()->is('subjects*')) active @endif">Предметы</a></li>
<li class="nav-item"><a href="{{ route('subjects.index') }}" class="nav-link @if(request()->is('subjects*')) active @endif">Предметы</a>
<li class="nav-item"><a href="{{ route('grades.lessons.grades-list') }}" class="nav-link @if(request()->is('grades/{grade}/lessons*')) active @endif">Занятия</a></li>
<li class="nav-item"><a href="{{ route('students.index') }}" class="nav-link @if(request()->is('students*')) active @endif">Ученики</a></li>
<li class="nav-item"><a href="{{ route('teachers.index') }}" class="nav-link @if(request()->is('teachers*')) active @endif">Учителя</a></li>
</ul>

View File

@ -19,9 +19,10 @@ Route::resources([
'subjects' => SubjectController::class,
'students' => StudentController::class,
'teachers' => TeacherController::class,
'lessons' => LessonController::class,
'grades.lessons' => LessonController::class,
]);
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::get('lessons/grade-list', [LessonController::class, 'gradeList'])->name('grades.lessons.grades-list');