Passed
Pull Request — develop (#11)
by
unknown
07:48 queued 03:43
created

CourseController::update()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Illuminate\Http\Request;
6
use App\Judite\Models\Course;
7
use Illuminate\Support\Facades\DB;
8
use App\Http\Controllers\Controller;
9
10
class CourseController extends Controller
11
{
12
    /**
13
     * Create a new controller instance.
14
     */
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
        $this->middleware('can.admin');
19
    }
20
21
    /**
22
     * Display a resource of given id.
23
     *
24
     * @param int $id
25
     *
26
     * @return \Illuminate\View\View
27
     */
28
    public function show($id)
29
    {
30
        $data = DB::transaction(function () use ($id) {
31
            $course = Course::findOrFail($id);
32
            $enrollments = $course->enrollments()
33
                ->with('student.user')
34
                ->orderByStudent()
35
                ->paginate();
36
37
            return compact('course', 'enrollments');
38
        });
39
40
        return view('students.index', $data);
41
    }
42
43
    /**
44
     * Update the specified resource in storage.
45
     *
46
     * @param \Illuminate\Http\Request $request
47
     * @param int                      $id
48
     *
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function update(Request $request, $id)
52
    {
53
        $course = Course::find($id);
54
55
        $min = $request->input('min');
56
        $max = $request->input('max');
57
58
        if ($min > $max) {
59
            $max = $min;
60
        }
61
62
        $course->group_min = $min;
63
        $course->group_max = $max;
64
65
        $course->save();
66
67
        return redirect()->route('admin.groups.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('admin.groups.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
68
    }
69
}
70