CourseController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use App\Judite\Models\Course;
6
use Illuminate\Support\Facades\DB;
7
use App\Http\Controllers\Controller;
8
9
class CourseController extends Controller
10
{
11
    /**
12
     * Create a new controller instance.
13
     */
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
        $this->middleware('can.admin');
18
    }
19
20
    /**
21
     * Display a resource of given id.
22
     *
23
     * @param int $id
24
     *
25
     * @return \Illuminate\View\View
26
     */
27
    public function show($id)
28
    {
29
        $data = DB::transaction(function () use ($id) {
30
            $course = Course::findOrFail($id);
31
            $enrollments = $course->enrollments()
32
                ->with('student.user')
33
                ->orderByStudent()
34
                ->paginate();
35
36
            return compact('course', 'enrollments');
37
        });
38
39
        return view('students.index', $data);
40
    }
41
}
42