college-courses/routes/web.php

65 lines
2.2 KiB
PHP
Raw Permalink Normal View History

2024-10-15 10:15:40 +03:00
<?php
use App\Http\Livewire\Course\CourseCreate;
use App\Http\Livewire\Course\CourseEdit;
use App\Http\Livewire\Course\CourseHomePage;
use App\Http\Livewire\Course\CourseManage;
use App\Http\Livewire\Lesson\LessonCreate;
use App\Http\Livewire\Lesson\LessonEdit;
use Illuminate\Support\Facades\Route;
use App\Http\Livewire\Login;
use App\Models\Course;
use App\Models\Lesson;
use Illuminate\Support\Facades\Auth;
// ====================
// Публичные маршруты
Route::get('/', function () {
return view('welcome');
});
// ====================
// Только гостевые маршруты
Route::middleware('guest')->group(function () {
Route::get('/login', Login::class)->name('login');
});
// ====================
// Закрытые маршруты
Route::middleware('auth')->group(function () {
// ====================
// Выход из системы
Route::get('/logout', function () {
Auth::logout();
return redirect('login');
});
// ====================
// Просмотр курсов и занятий
Route::view('/catalog', 'course-catalog')->name('catalog');
Route::get('/course/{course}', CourseHomePage::class)->name('course-index');
Route::get('/course/{course}/{lesson}', function (Course $course, $lesson) {
$isExists = Lesson::query()->where('slug', $lesson)->where('course_id', $course->id)->exists();
if ($isExists) {
return view('course-lesson', ['course' => $course, 'lesson' => $course->getLesson($lesson)]);
}
return abort(404);
})->name('lesson');
// ====================
// Управление курсами
Route::get('/manage/course', CourseManage::class)->name('course-manage');
Route::get('/manage/create/course', CourseCreate::class)->name('course-create')->can('course-create');
Route::middleware('can:course-update,course')->group(function () {
Route::get('/manage/course/{course}', CourseEdit::class)->name('course-edit');
Route::get('/manage/course/{course}/lesson', LessonCreate::class)->name('lesson-create');
Route::get('/manage/course/{course}/lesson/{lesson}', LessonEdit::class)->name('lesson-edit');
});
});