Added views, controllers, services

This commit is contained in:
m.zargarov 2024-04-23 14:52:49 +04:00
parent 0485df95cf
commit 2807140c65
29 changed files with 797 additions and 94 deletions

View File

@ -4,19 +4,23 @@ namespace App\Http\Controllers;
use App\Http\Requests\GradePostRequest;
use App\Models\Grade;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class GradeController extends Controller
{
public function __construct(
protected ServiceInterface $gradeService,
){}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('grades.index', [
'grades' => Grade::filter()->paginate(10)->withQueryString(),
'grades' => $this->gradeService->getAll(),
]);
}
@ -33,9 +37,7 @@ class GradeController extends Controller
*/
public function store(GradePostRequest $request): RedirectResponse
{
$grade = Grade::create($request->validated());
return redirect()->route('grades.show', $grade);
return redirect()->route('grades.show', $this->gradeService->create($request->validated()));
}
/**
@ -63,9 +65,7 @@ class GradeController extends Controller
*/
public function update(GradePostRequest $request, Grade $grade): RedirectResponse
{
$grade->update($request->validated());
return redirect()->route('grades.show', $grade);
return redirect()->route('grades.show', $this->gradeService->update($grade, $request->validated()));
}
/**
@ -73,7 +73,7 @@ class GradeController extends Controller
*/
public function destroy(Grade $grade): RedirectResponse
{
$grade->delete();
$this->gradeService->delete($grade);
return redirect()->route('grades.index');
}

View File

@ -0,0 +1,91 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\StudentPostRequest;
use App\Models\Grade;
use App\Models\Student;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class StudentController extends Controller
{
public function __construct(
protected ServiceInterface $studentService
){}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('students.index', [
'students' => $this->studentService->getAll(),
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('students.create', [
'grades' => Grade::all(),
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(StudentPostRequest $request): RedirectResponse
{
return redirect()->route(
'students.show',
$this->studentService->create($request->validated())
);
}
/**
* Display the specified resource.
*/
public function show(Student $student): View
{
return view('students.show', [
'student' => $student,
'grades' => Grade::all(),
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Student $student): View
{
return view('students.edit', [
'student' => $student,
'grades' => Grade::all(),
]);
}
/**
* Update the specified resource in storage.
*/
public function update(StudentPostRequest $request, Student $student): RedirectResponse
{
return redirect()->route(
'students.show',
$this->studentService->update($student, $request->validated())
);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Student $student): RedirectResponse
{
$this->studentService->delete($student);
return redirect()->route('students.index');
}
}

View File

@ -4,19 +4,23 @@ namespace App\Http\Controllers;
use App\Http\Requests\SubjectPostRequest;
use App\Models\Subject;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class SubjectController extends Controller
{
public function __construct(
protected ServiceInterface $subjectService,
){}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('subjects.index', [
"subjects" => Subject::filter()->paginate(10)->withQueryString(),
"subjects" => $this->subjectService->getAll(),
]);
}
@ -33,9 +37,10 @@ class SubjectController extends Controller
*/
public function store(SubjectPostRequest $request): RedirectResponse
{
$subject = Subject::create($request->validated());
return redirect()->route('subjects.show', $subject);
return redirect()->route(
'subjects.show',
$this->subjectService->create($request->validated())
);
}
/**
@ -63,9 +68,10 @@ class SubjectController extends Controller
*/
public function update(SubjectPostRequest $request, Subject $subject): RedirectResponse
{
$subject->update($request->validated());
return redirect()->route('subjects.show', $subject);
return redirect()->route(
'subjects.show',
$this->subjectService->update($subject, $request->validated())
);
}
/**
@ -73,7 +79,7 @@ class SubjectController extends Controller
*/
public function destroy(Subject $subject): RedirectResponse
{
$subject->delete();
$this->subjectService->delete($subject);
return redirect()->route('subjects.index');
}

View File

@ -0,0 +1,86 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\TeacherPostRequest;
use App\Models\Teacher;
use App\Services\ServiceInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class TeacherController extends Controller
{
public function __construct(
protected ServiceInterface $teacherService
){}
/**
* Display a listing of the resource.
*/
public function index(): View
{
return view('teachers.index', [
'teachers' => $this->teacherService->getAll(),
]);
}
/**
* Show the form for creating a new resource.
*/
public function create(): View
{
return view('teachers.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(TeacherPostRequest $request): RedirectResponse
{
return redirect()->route(
'teachers.show',
$this->teacherService->create($request->validated())
);
}
/**
* Display the specified resource.
*/
public function show(Teacher $teacher): View
{
return view('teachers.show', [
'teacher' => $teacher,
]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Teacher $teacher): View
{
return view('teachers.edit', [
'teacher' => $teacher,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(TeacherPostRequest $request, Teacher $teacher): RedirectResponse
{
return redirect()->route(
'teachers.show',
$this->teacherService->update($teacher, $request->validated())
);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Teacher $teacher): RedirectResponse
{
$this->teacherService->delete($teacher);
return redirect()->route('teachers.index');
}
}

View File

@ -1,64 +0,0 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Http\Requests;
use App\Enums\RoleEnum;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class StudentPostRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|max:255',
'last_name' => 'required|max:255',
'middle_name' => 'required|max:255',
'birthday' => 'required|date',
'grade_id' => 'required|exists:grades,id',
'login' => 'required|max:255|lowercase|unique:users,login',
'password' => 'required|max:255',
];
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Http\Requests;
use App\Enums\RoleEnum;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class TeacherPostRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'name' => 'required|max:255',
'last_name' => 'required|max:255',
'middle_name' => 'required|max:255',
'birthday' => 'required|date',
'login' => 'required|max:255|lowercase|unique:users,login',
'password' => 'required|max:255',
];
}
}

View File

@ -10,12 +10,6 @@ class Admin extends Model
{
use HasFactory;
protected $fillable = [
'name',
'last_name',
'middle_name',
];
public function user(): MorphOne
{
return $this->morphOne(User::class, 'userable');

View File

@ -5,7 +5,8 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Builder;
class Student extends Model
{
use HasFactory;
@ -21,4 +22,22 @@ class Student extends Model
{
return $this->belongsTo(Grade::class);
}
public function user(): MorphOne
{
return $this->morphOne(User::class, 'userable');
}
public function scopeFilter(Builder $query): void
{
$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%"]);
});
}
}

View File

@ -6,7 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Builder;
class Teacher extends Model
{
use HasFactory;
@ -32,4 +32,17 @@ class Teacher extends Model
{
return $this->morphOne(User::class, 'userable');
}
public function scopeFilter(Builder $query): void
{
$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%"]);
});
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace App\Providers;
use App\Http\Controllers\GradeController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectController;
use App\Http\Controllers\TeacherController;
use App\Services\GradeService;
use App\Services\ServiceInterface;
use App\Services\StudentService;
use App\Services\SubjectService;
use App\Services\TeacherService;
use Illuminate\Support\ServiceProvider;
class ModelServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->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(GradeController::class)
->needs(ServiceInterface::class)
->give(function () {
return new GradeService();
});
$this->app->when(SubjectController::class)
->needs(ServiceInterface::class)
->give(function () {
return new SubjectService();
});
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Services;
use App\Models\Grade;
use Illuminate\Pagination\LengthAwarePaginator;
class GradeService implements ServiceInterface
{
public function getAll(): LengthAwarePaginator
{
return Grade::filter()->paginate(10)->withQueryString();
}
public function create(array $data): Grade
{
return Grade::create($data);
}
public function update($model, array $data): Grade
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->delete();
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace App\Services;
interface ServiceInterface
{
public function getAll();
public function create(array $data);
public function update($model, array $data);
public function delete($model);
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Services;
use App\Models\Student;
use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator;
class StudentService implements ServiceInterface
{
public function getAll(): LengthAwarePaginator
{
return Student::filter()->paginate(10)->withQueryString();
}
public function create(array $data): User
{
$user = User::create($data['credentials']);
$student = Student::create($data['user_data']);
$student->user()->save($user);
return $student;
}
public function update($model, array $data): User
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->destroy();
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Services;
use App\Models\Subject;
use Illuminate\Pagination\LengthAwarePaginator;
class SubjectService implements ServiceInterface
{
public function getAll(): LengthAwarePaginator
{
return Subject::filter()->paginate(10)->withQueryString();
}
public function create(array $data): Subject
{
return Subject::create($data);
}
public function update($model, array $data): Subject
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->delete();
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\Services;
use App\Models\Teacher;
use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator;
class TeacherService implements ServiceInterface
{
public function getAll(): LengthAwarePaginator
{
return Teacher::filter()->paginate(10)->withQueryString();
}
public function create(array $data): User
{
$user = User::create($data['credentials']);
$teacher = Teacher::create($data['user_data']);
$teacher->user()->save($user);
return $teacher;
}
public function update($model, array $data): User
{
$model->update($data);
return $model;
}
public function delete($model): void
{
$model->destroy();
}
}

View File

@ -2,4 +2,5 @@
return [
App\Providers\AppServiceProvider::class,
App\Providers\ModelServiceProvider::class,
];

View File

@ -1,9 +1,10 @@
<div class="container">
<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('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('users.index') }}" class="nav-link @if(request()->is('users*')) 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>
</header>
</div>

View File

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

View File

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

View File

@ -0,0 +1,40 @@
<div class="container col-md-6">
<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($student) ? $student->name : old('name') }}" required>
</div>
<div class="mb-3">
<label for="last_name" class="form-label">Фамилия:</label>
<input type="text" id="last_name" name="last_name" class="form-control" value="{{ isset($student) ? $student->last_name : old('last_name') }}" required>
</div>
<div class="mb-3">
<label for="middle_name" class="form-label">Отчество:</label>
<input type="text" id="middle_name" name="middle_name" class="form-control" value="{{ isset($student) ? $student->middle_name : old('middle_name') }}" required>
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Дата рождения:</label>
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($student) ? $student->birthday : old('birthday') }}" required>
</div>
<div class="mb-3">
<label for="grade_id" class="form-label">Класс:</label>
<select id="grade_id" name="grade_id" class="form-select" required>
<option value="">Выберите класс</option>
@foreach($grades as $grade)
<option value="{{ $grade->id }}" {{ isset($student) && $student->grade_id == $grade->id ? 'selected' : '' }}>
{{ $grade->name }}
</option>
@endforeach
</select>
</div>
<button type="submit" class="btn btn-success">Подтвердить</button>
</form>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,66 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-6">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">{{__('Новый ученик')}}</div>
<div class="card-body">
<a href="{{ route('students.create') }}" class="btn btn-success">Добавить</a>
</div>
</div>
<div class="card mt-4">
<div class="card-header">{{__('Поиск ученика')}}</div>
<div class="card-body">
<form action="{{ route('students.index') }}" method="GET">
<div class="mb-3">
<label for="name" class="form-label">ФИО:</label>
<input type="text" id="name" name="name" class="form-control" value="{{ request('name') ?? '' }}">
</div>
<div>
<button type="submit" class="btn btn-primary">Фильтр</button>
</div>
</form>
</div>
</div>
@if (count($students))
<div class="card mt-4">
<div class="card-header">{{__('Ученики')}}</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<th>Ученик</th>
<th>&nbsp;</th>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td class="table-text">
<div>
<a href="{{ route('students.show', $student) }}" class="btn btn-block col-8">{{ $student->last_name }} {{ $student->name }} {{ $student->middle_name }}</a>
</div>
</td>
<td>
<div>
<a href="{{ route('students.edit', $student) }}" class="btn btn-warning">Редактировать</a>
</div>
</td>
<td>
<form action="{{ route('students.destroy', $student) }}" method="POST" style="display: inline-block;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer">{{ $students->links() }}</div>
</div>
@endif
</div>
</div>
@endsection

View File

@ -0,0 +1,26 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-6">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">{{ ('Ученик') }}</div>
<div class="card-body">
<div class="mb-3">
<h5><strong>ФИО: </strong>{{ $user->last_name }} {{ $user->name }} {{ $user->middle_name }}</h5>
</div>
<div class="mb-3">
<h5><strong>Класс: </strong>{{ $user->class->name }}</h5>
</div>
<div class="mb-3">
<h5><strong>Дата рождения: </strong>{{ $user->birthday }}</h5>
</div>
</div>
<div class="card-footer">
<a href="{{ route('users.edit', $user) }}" class="btn btn-primary">Редактировать</a>
</div>
</div>
</div>
</div>
@endsection

View File

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

View File

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

View File

@ -0,0 +1,37 @@
<div class="container col-md-6">
<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($teacher) ? $teacher->name : old('name') }}" required>
</div>
<div class="mb-3">
<label for="last_name" class="form-label">Фамилия:</label>
<input type="text" id="last_name" name="last_name" class="form-control" value="{{ isset($teacher) ? $teacher->last_name : old('last_name') }}" required>
</div>
<div class="mb-3">
<label for="middle_name" class="form-label">Отчество:</label>
<input type="text" id="middle_name" name="middle_name" class="form-control" value="{{ isset($teacher) ? $teacher->middle_name : old('middle_name') }}" required>
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Дата рождения:</label>
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Логин:</label>
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
</div>
<div class="mb-3">
<label for="birthday" class="form-label">Пароль:</label>
<input type="date" id="birthday" name="birthday" class="form-control" value="{{ isset($teacher) ? $teacher->birthday : old('birthday') }}" required>
</div>
<button type="submit" class="btn btn-success">Подтвердить</button>
</form>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,66 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-6">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">{{__('Новый учитель')}}</div>
<div class="card-body">
<a href="{{ route('teachers.create') }}" class="btn btn-success">Добавить</a>
</div>
</div>
<div class="card mt-4">
<div class="card-header">{{__('Поиск учителя')}}</div>
<div class="card-body">
<form action="{{ route('teachers.index') }}" method="GET">
<div class="mb-3">
<label for="name" class="form-label">ФИО:</label>
<input type="text" id="name" name="name" class="form-control" value="{{ request('name') ?? '' }}">
</div>
<div>
<button type="submit" class="btn btn-primary">Фильтр</button>
</div>
</form>
</div>
</div>
@if (count($teachers))
<div class="card mt-4">
<div class="card-header">{{__('Учителя')}}</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<th>Ученик</th>
<th>&nbsp;</th>
</thead>
<tbody>
@foreach ($teachers as $teacher)
<tr>
<td class="table-text">
<div>
<a href="{{ route('teachers.show', $teacher) }}" class="btn btn-block col-8">{{ $teacher->last_name }} {{ $teacher->name }} {{ $teacher->middle_name }}</a>
</div>
</td>
<td>
<div>
<a href="{{ route('teachers.edit', $teacher) }}" class="btn btn-warning">Редактировать</a>
</div>
</td>
<td>
<form action="{{ route('teachers.destroy', $teacher) }}" method="POST" style="display: inline-block;">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="card-footer">{{ $teachers->links() }}</div>
</div>
@endif
</div>
</div>
@endsection

View File

@ -0,0 +1,23 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-6">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">{{ ('Учитель') }}</div>
<div class="card-body">
<div class="mb-3">
<h5><strong>ФИО: </strong>{{ $user->last_name }} {{ $user->name }} {{ $user->middle_name }}</h5>
</div>
<div class="mb-3">
<h5><strong>Дата рождения: </strong>{{ $user->birthday }}</h5>
</div>
</div>
<div class="card-footer">
<a href="{{ route('users.edit', $user) }}" class="btn btn-primary">Редактировать</a>
</div>
</div>
</div>
</div>
@endsection

View File

@ -1,8 +1,9 @@
<?php
use App\Http\Controllers\GradeController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\TeacherController;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
@ -11,4 +12,5 @@ Route::get('/', function () {
Route::resource('grades', GradeController::class);
Route::resource('subjects', SubjectController::class);
Route::resource('users', UserController::class);
Route::resource('students', StudentController::class);
Route::resource('teachers', TeacherController::class);