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'); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|