diff --git a/app/Http/Controllers/GradeSubjectController.php b/app/Http/Controllers/GradeSubjectController.php index 365b46a..d7ee45d 100644 --- a/app/Http/Controllers/GradeSubjectController.php +++ b/app/Http/Controllers/GradeSubjectController.php @@ -11,11 +11,6 @@ use Illuminate\View\View; class GradeSubjectController extends Controller { - public function __construct( - protected ServiceInterface $service, - ) { - } - public function create(Grade $grade): View { return view('grade-subject.create', [ @@ -28,7 +23,7 @@ class GradeSubjectController extends Controller { $grade->subjects()->syncWithoutDetaching($request->subject_id); - return redirect()->route('grades.show', $this->service->create($request->validated(), $grade)); + return redirect()->route('grades.show', $grade); } public function edit(Grade $grade, Subject $subject): View @@ -42,12 +37,16 @@ class GradeSubjectController extends Controller public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse { - return redirect()->route('grades.show', - $this->service->update($grade, $request->validated(), $subject)); + $grade->subjects()->detach($subject); + $grade->subjects()->attach($request->subject_id); + + return redirect()->route('grades.show', $grade); } public function destroy(Grade $grade, Subject $subject): RedirectResponse { - return redirect()->route('grades.show', $this->service->delete($grade, $subject)); + $grade->subjects()->detach($subject); + + return redirect()->route('grades.show', $grade); } } diff --git a/app/Http/Controllers/GradeTeacherController.php b/app/Http/Controllers/GradeTeacherController.php index 735d459..64e6bd2 100644 --- a/app/Http/Controllers/GradeTeacherController.php +++ b/app/Http/Controllers/GradeTeacherController.php @@ -12,24 +12,21 @@ use Illuminate\View\View; class GradeTeacherController extends Controller { - public function __construct( - protected ServiceInterface $service, - ) { - } - public function create(Teacher $teacher, Subject $subject): View { return view('grade-teacher.create', [ 'teacher' => $teacher, 'subject' => $subject, - 'grades' => $this->service->getGrades($subject), + 'grades' => $subject->grades, ]); } public function store(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse { + $teacher->grades()->syncWithoutDetaching($request->grade_id); + return redirect()->route('teachers.subjects.show', [ - $this->service->create($request->validated(), $teacher), + $teacher, $subject, ]); } @@ -40,22 +37,27 @@ class GradeTeacherController extends Controller 'teacher' => $teacher, 'subject' => $subject, 'updateGrade' => $grade, - 'grades' => $this->service->getGrades($subject), + 'grades' => $subject->grades, ]); } public function update(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse { + $teacher->grades()->detach($grade); + $teacher->grades()->attach($request->grade_id); + return redirect()->route('teachers.subjects.show', [ - $this->service->update($teacher, $request->validated(), $grade), + $teacher, $subject, ]); } public function destroy(Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse { + $teacher->grades()->detach($grade); + return redirect()->route('teachers.subjects.show', [ - $this->service->delete($teacher, $grade), + $teacher, $subject, ]); } diff --git a/app/Http/Controllers/LessonController.php b/app/Http/Controllers/LessonController.php index 816f9e6..f9dec72 100644 --- a/app/Http/Controllers/LessonController.php +++ b/app/Http/Controllers/LessonController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Enums\ScoreEnum; use App\Enums\TypeLesson; use App\Http\Requests\LessonPostRequest; use App\Models\Grade; @@ -12,12 +13,6 @@ use Illuminate\View\View; class LessonController extends Controller { - public function __construct - ( - protected ServiceInterface $service, - ){ - } - public function gradeList(): View { return view('grade-lesson.grades-list', [ @@ -53,10 +48,15 @@ class LessonController extends Controller */ public function store(LessonPostRequest $request, Grade $grade): RedirectResponse { + $lesson = Lesson::create($request->validated()); + $lesson + ->students() + ->syncWithPivotValues($lesson->grade->students->pluck('id')->all(), ['score' => ScoreEnum::WithoutScore]); + return redirect()->route( 'grades.lessons.show', [ $grade, - $this->service->create($request->validated()) + $lesson, ] ); } @@ -92,7 +92,7 @@ class LessonController extends Controller return redirect()->route( 'grades.lessons.show',[ $grade, - $this->service->update($lesson, $request->validated()) + $lesson->update($request->validated()), ] ); } @@ -102,7 +102,7 @@ class LessonController extends Controller */ public function destroy(Grade $grade, Lesson $lesson): RedirectResponse { - $this->service->delete($lesson); + $lesson->delete(); return redirect()->route('grades.lessons.index', $grade); } diff --git a/app/Http/Controllers/ScoreController.php b/app/Http/Controllers/ScoreController.php index 838ab9b..4bc97af 100644 --- a/app/Http/Controllers/ScoreController.php +++ b/app/Http/Controllers/ScoreController.php @@ -4,6 +4,7 @@ namespace App\Http\Controllers; use App\Enums\ScoreEnum; use App\Models\Lesson; +use App\Services\ScoreService; use App\Services\ServiceInterface; use Illuminate\Http\Request; @@ -11,14 +12,14 @@ class ScoreController extends Controller { public function __construct( - protected ServiceInterface $service, + protected ScoreService $service, ){ } public function show(Lesson $lesson) { return view('scores.show', [ - 'students' => $this->service->getAll($lesson), + 'students' => $lesson->students, 'lesson' => $lesson, 'scores' => ScoreEnum::cases(), ]); diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index fa76501..5217ca6 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -6,13 +6,14 @@ use App\Http\Requests\StudentPostRequest; use App\Models\Grade; use App\Models\Student; use App\Services\ServiceInterface; +use App\Services\StudentService; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; class StudentController extends Controller { public function __construct( - protected ServiceInterface $service + protected StudentService $service ) { } @@ -22,7 +23,7 @@ class StudentController extends Controller public function index(): View { return view('students.index', [ - 'students' => $this->service->getAll(), + 'students' => Student::filter()->paginate(5)->withQueryString(), ]); } @@ -85,7 +86,8 @@ class StudentController extends Controller */ public function destroy(Student $student): RedirectResponse { - $this->service->delete($student); + $student->user()->delete(); + $student->delete(); return redirect()->route('students.index'); } diff --git a/app/Http/Controllers/SubjectController.php b/app/Http/Controllers/SubjectController.php index 58e670f..1e7733d 100644 --- a/app/Http/Controllers/SubjectController.php +++ b/app/Http/Controllers/SubjectController.php @@ -10,18 +10,13 @@ use Illuminate\View\View; class SubjectController extends Controller { - public function __construct( - protected ServiceInterface $service, - ) { - } - /** * Display a listing of the resource. */ public function index(): View { return view('subjects.index', [ - 'subjects' => $this->service->getAll(), + 'subjects' => Subject::filter()->paginate(5)->withQueryString(), ]); } @@ -40,7 +35,7 @@ class SubjectController extends Controller { return redirect()->route( 'subjects.show', - $this->service->create($request->validated()) + Subject::create($request->validated()), ); } @@ -71,7 +66,7 @@ class SubjectController extends Controller { return redirect()->route( 'subjects.show', - $this->service->update($subject, $request->validated()) + $subject->update($request->validated()) ); } @@ -80,7 +75,7 @@ class SubjectController extends Controller */ public function destroy(Subject $subject): RedirectResponse { - $this->service->delete($subject); + $subject->delete(); return redirect()->route('subjects.index'); } diff --git a/app/Http/Controllers/SubjectTeacherController.php b/app/Http/Controllers/SubjectTeacherController.php index eb8db9a..efa3299 100644 --- a/app/Http/Controllers/SubjectTeacherController.php +++ b/app/Http/Controllers/SubjectTeacherController.php @@ -11,22 +11,19 @@ use Illuminate\View\View; class SubjectTeacherController extends Controller { - public function __construct( - protected ServiceInterface $service, - ) { - } - public function create(Teacher $teacher): View { return view('subject-teacher.create', [ 'teacher' => $teacher, - 'subjects' => $this->service->getAllSubjects(), + 'subjects' => Subject::all(), ]); } public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse { - return redirect()->route('teachers.show', $this->service->create($request->validated(), $teacher)); + $teacher->subjects()->syncWithoutDetaching($request->subject_id); + + return redirect()->route('teachers.show', $teacher); } public function show(Teacher $teacher, Subject $subject): View @@ -34,7 +31,10 @@ class SubjectTeacherController extends Controller return view('subject-teacher.show', [ 'teacher' => $teacher, 'subject' => $subject, - 'grades' => $this->service->getGrades($teacher, $subject), + 'grades' => $teacher + ->grades() + ->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id') + ->where('subject_id', $subject->id)->get(), ]); } @@ -43,18 +43,22 @@ class SubjectTeacherController extends Controller return view('subject-teacher.edit', [ 'teacher' => $teacher, 'updateSubject' => $subject, - 'subjects' => $this->service->getAllSubjects(), + 'subjects' => Subject::all(), ]); } public function update(SubjectTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse { - return redirect()->route('teachers.show', - $this->service->update($teacher, $request->validated(), $subject)); + $teacher->subjects()->detach($subject); + $teacher->subjects()->attach($request->subject_id); + + return redirect()->route('teachers.show', $teacher); } public function destroy(Teacher $teacher, Subject $subject): RedirectResponse { - return redirect()->route('teachers.show', $this->service->delete($teacher, $subject)); + $teacher->subjects()->detach($subject); + + return redirect()->route('teachers.show', $teacher); } } diff --git a/app/Http/Controllers/TeacherController.php b/app/Http/Controllers/TeacherController.php index f82ffda..edaa9e0 100644 --- a/app/Http/Controllers/TeacherController.php +++ b/app/Http/Controllers/TeacherController.php @@ -5,13 +5,14 @@ namespace App\Http\Controllers; use App\Http\Requests\TeacherPostRequest; use App\Models\Teacher; use App\Services\ServiceInterface; +use App\Services\TeacherService; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; class TeacherController extends Controller { public function __construct( - protected ServiceInterface $service + protected TeacherService $service ) { } @@ -21,7 +22,7 @@ class TeacherController extends Controller public function index(): View { return view('teachers.index', [ - 'teachers' => $this->service->getAll(), + 'teachers' => Teacher::filter()->paginate(5)->withQueryString(), ]); } @@ -81,7 +82,8 @@ class TeacherController extends Controller */ public function destroy(Teacher $teacher): RedirectResponse { - $this->service->delete($teacher); + $teacher->user()->delete(); + $teacher->delete(); return redirect()->route('teachers.index'); } diff --git a/app/Models/Student.php b/app/Models/Student.php index b7f93d0..fdc1552 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -46,12 +46,12 @@ class Student extends Model { $name = request('name'); $query->when($name, function (Builder $query, $name) { - $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (surname, \' \', patronymic, \' \', name) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (patronymic, \' \', name, \' \', surname) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]); + $query->whereRaw('CONCAT (name, \' \', last_name, \' \', middle_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (name, \' \', middle_name, \' \', last_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (last_name, \' \', name, \' \', middle_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (last_name, \' \', middle_name, \' \', name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (middle_name, \' \', name, \' \', last_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (middle_name, \' \', last_name, \' \', name) ilike ?', ["$name%"]); }); } diff --git a/app/Models/Teacher.php b/app/Models/Teacher.php index 0ce1e37..112f79e 100644 --- a/app/Models/Teacher.php +++ b/app/Models/Teacher.php @@ -45,12 +45,12 @@ class Teacher extends Model { $name = request('name'); $query->when($name, function (Builder $query, $name) { - $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (surname, \' \', patronymic, \' \', name) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (patronymic, \' \', name, \' \', surname) ilike ?', ["$name%"]); - $query->orWhereRaw('CONCAT (patronymic, \' \', surname, \' \', name) ilike ?', ["$name%"]); + $query->whereRaw('CONCAT (name, \' \', last_name, \' \', middle_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (name, \' \', middle_name, \' \', last_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (last_name, \' \', name, \' \', middle_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (last_name, \' \', middle_name, \' \', name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (middle_name, \' \', name, \' \', last_name) ilike ?', ["$name%"]); + $query->orWhereRaw('CONCAT (middle_name, \' \', last_name, \' \', name) ilike ?', ["$name%"]); }); } diff --git a/app/Providers/ModelServiceProvider.php b/app/Providers/ModelServiceProvider.php deleted file mode 100644 index d90eeee..0000000 --- a/app/Providers/ModelServiceProvider.php +++ /dev/null @@ -1,90 +0,0 @@ -app->when(StudentController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new StudentService(); - }); - - $this->app->when(TeacherController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new TeacherService(); - }); - - $this->app->when(SubjectController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new SubjectService(); - }); - - $this->app->when(SubjectTeacherController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new SubjectTeacherService(); - }); - - $this->app->when(GradeSubjectController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new GradeSubjectService(); - }); - - $this->app->when(GradeTeacherController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new GradeTeacherService(); - }); - - $this->app->when(LessonController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new LessonService(); - }); - - - $this->app->when(ScoreController::class) - ->needs(ServiceInterface::class) - ->give(function () { - return new ScoreService(); - }); - } - - /** - * Bootstrap services. - */ - public function boot(): void - { - // - } -} diff --git a/app/Services/GradeSubjectService.php b/app/Services/GradeSubjectService.php deleted file mode 100644 index 55d4793..0000000 --- a/app/Services/GradeSubjectService.php +++ /dev/null @@ -1,43 +0,0 @@ -subjects; - } - - public function getAllSubjects(): Collection - { - return Subject::all(); - } - - public function create(array $data, ?Model $model = null): Grade - { - $model->subjects()->syncWithoutDetaching($data['subject_id']); - - return $model; - } - - public function update(Model $model, array $data, ?Model $subject = null): Grade - { - $model->subjects()->detach($subject->id); - $model->subjects()->attach($data['subject_id']); - - return $model; - } - - public function delete(Model $model, ?Model $subject = null): Grade - { - $model->subjects()->detach($subject); - - return $model; - } -} diff --git a/app/Services/GradeTeacherService.php b/app/Services/GradeTeacherService.php deleted file mode 100644 index 4ed24bc..0000000 --- a/app/Services/GradeTeacherService.php +++ /dev/null @@ -1,47 +0,0 @@ -grades() - ->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id') - ->where('subject_id', $subject->id) - ->get(); - } - - public function getGrades(Subject $subject): Collection - { - return $subject->grades; - } - - public function create(array $data, ?Model $model = null): Teacher - { - $model->grades()->syncWithoutDetaching($data['grade_id']); - - return $model; - } - - public function update(Model $model, array $data, ?Model $grade = null): Teacher - { - $model->grades()->detach($grade->id); - $model->grades()->attach($data['grade_id']); - - return $model; - } - - public function delete(Model $model, ?Model $grade = null): Teacher - { - $model->grades()->detach($grade); - - return $model; - } -} diff --git a/app/Services/LessonService.php b/app/Services/LessonService.php deleted file mode 100644 index dc59737..0000000 --- a/app/Services/LessonService.php +++ /dev/null @@ -1,45 +0,0 @@ -lessons()->filter()->get(); - } - - public function getGrades(): Collection - { - return Grade::all(); - } - - public function create(array $data): Lesson - { - $lesson = Lesson::create($data); - $lesson - ->students() - ->syncWithPivotValues($lesson->grade->students->pluck('id')->all(), ['score' => ScoreEnum::WithoutScore]); - - return $lesson; - } - - public function update(Model $model, array $data): Lesson - { - $model->update($data); - - return $model; - } - - public function delete($model): void - { - $model->delete(); - } -} diff --git a/app/Services/ScoreService.php b/app/Services/ScoreService.php index 03d0a90..a2855ac 100644 --- a/app/Services/ScoreService.php +++ b/app/Services/ScoreService.php @@ -5,32 +5,16 @@ namespace App\Services; use App\Models\Lesson; use Illuminate\Database\Eloquent\Model; -class ScoreService implements ServiceInterface +class ScoreService { - - public function getAll(?Lesson $lesson = null) + public function update(Lesson $lesson, array $data) { - return $lesson->students; - } - - public function update(Model $model, array $data) - { - $model->students->each(function ($item, $key) use ($data, $model) { + $lesson->students->each(function ($item, $key) use ($data, $lesson) { if ($data['score' . $item->id]) { - $model->students()->syncWithoutDetaching([$item->id => ['score' => $data['score' . $item->id]]]); + $lesson->students()->syncWithoutDetaching([$item->id => ['score' => $data['score' . $item->id]]]); } }); - return $model; - } - - public function delete(Model $model) - { - // TODO: Implement delete() method. - } - - public function create(array $data) - { - // TODO: Implement create() method. + return $lesson; } } diff --git a/app/Services/ServiceInterface.php b/app/Services/ServiceInterface.php deleted file mode 100644 index d4b6d33..0000000 --- a/app/Services/ServiceInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -paginate(5)->withQueryString(); - } - public function create(array $data): Student { $user = User::create([ @@ -35,14 +30,14 @@ class StudentService implements ServiceInterface return $student; } - public function update($model, array $data): Student + public function update(Student $student, array $data): Student { - $model->user()->update([ + $student->user()->update([ 'email' => $data['email'], 'password' => $data['password'], ]); - $model->update([ + $student->update([ 'name' => $data['name'], 'last_name' => $data['last_name'], 'middle_name' => $data['middle_name'], @@ -50,7 +45,7 @@ class StudentService implements ServiceInterface 'grade_id' => $data['grade_id'], ]); - return $model; + return $student; } public function delete($model): void diff --git a/app/Services/SubjectService.php b/app/Services/SubjectService.php deleted file mode 100644 index 6687465..0000000 --- a/app/Services/SubjectService.php +++ /dev/null @@ -1,32 +0,0 @@ -paginate(5)->withQueryString(); - } - - public function create(array $data): Subject - { - return Subject::create($data); - } - - public function update(Model $model, array $data): Subject - { - $model->update($data); - - return $model; - } - - public function delete(Model $model): void - { - $model->delete(); - } -} diff --git a/app/Services/SubjectTeacherService.php b/app/Services/SubjectTeacherService.php deleted file mode 100644 index 8e22055..0000000 --- a/app/Services/SubjectTeacherService.php +++ /dev/null @@ -1,51 +0,0 @@ -subjects; - } - - public function getAllSubjects(): Collection - { - return Subject::all(); - } - - public function getGrades(Teacher $teacher, Subject $subject): Collection - { - return $teacher - ->grades() - ->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id') - ->where('subject_id', $subject->id)->get(); - } - - public function create(array $data, ?Model $model = null): Teacher - { - $model->subjects()->syncWithoutDetaching($data['subject_id']); - - return $model; - } - - public function update(Model $model, array $data, ?Model $subject = null): Teacher - { - $model->subjects()->detach($subject->id); - $model->subjects()->attach($data['subject_id']); - - return $model; - } - - public function delete(Model $model, ?Model $subject = null): Teacher - { - $model->subjects()->detach($subject); - - return $model; - } -} diff --git a/app/Services/TeacherService.php b/app/Services/TeacherService.php index ea04740..4059882 100644 --- a/app/Services/TeacherService.php +++ b/app/Services/TeacherService.php @@ -6,13 +6,8 @@ use App\Models\Teacher; use App\Models\User; use Illuminate\Pagination\LengthAwarePaginator; -class TeacherService implements ServiceInterface +class TeacherService { - public function getAll(): LengthAwarePaginator - { - return Teacher::filter()->paginate(5)->withQueryString(); - } - public function create(array $data): Teacher { $user = User::create([ @@ -30,26 +25,26 @@ class TeacherService implements ServiceInterface return $teacher; } - public function update($model, array $data): Teacher + public function update(Teacher $teacher, array $data): Teacher { - $model->user()->update([ + $teacher->user()->update([ 'email' => $data['email'], 'password' => $data['password'], ]); - $model->update([ + $teacher->update([ 'name' => $data['name'], 'last_name' => $data['last_name'], 'middle_name' => $data['middle_name'], 'birthday' => $data['birthday'], ]); - return $model; + return $teacher; } - public function delete($model): void + public function delete(Teacher $teacher): void { - $model->user()->delete(); - $model->delete(); + $teacher->user()->delete(); + $teacher->delete(); } } diff --git a/bootstrap/providers.php b/bootstrap/providers.php index da9f844..d544739 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -2,6 +2,5 @@ return [ App\Providers\AppServiceProvider::class, - App\Providers\ModelServiceProvider::class, App\Providers\TelescopeServiceProvider::class, ]; diff --git a/vite.config.js b/vite.config.js index 89f26f5..6db9f91 100644 --- a/vite.config.js +++ b/vite.config.js @@ -6,6 +6,7 @@ export default defineConfig({ laravel({ input: [ 'resources/css/app.css', + 'resources/sass/app.scss', 'resources/js/app.js', ], refresh: true,