-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseController.php
More file actions
51 lines (43 loc) · 1.3 KB
/
CourseController.php
File metadata and controls
51 lines (43 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Course;
use Inertia\Inertia;
use Inertia\Response;
final class CourseController extends Controller
{
/**
* Display a list of published courses.
*/
public function index(): Response
{
$courses = Course::where('is_published', true)
->select('id', 'title', 'slug', 'description')
->get();
return Inertia::render('courses/Index', [
'courses' => $courses,
]);
}
/**
* Display a single course with its modules and lessons.
*/
public function show(Course $course): Response
{
if (! $course->is_published) {
abort(404);
}
$course->load([
'modules.lessons' => function ($query): void {
$query->select('id', 'module_id', 'title', 'slug', 'order');
}, 'modules.quizzes' => function ($query): void {
$query->select('id', 'module_id', 'title', 'description', 'order')
->orderBy('order');
},
'modules' => function ($query): void {
$query->select('id', 'course_id', 'title', 'order');
}]);
return Inertia::render('courses/Show', [
'course' => $course,
]);
}
}