1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Judite\Models\Group; |
6
|
|
|
use Illuminate\Support\Facades\DB; |
7
|
|
|
use Illuminate\Support\Facades\Auth; |
8
|
|
|
|
9
|
|
|
class GroupStudentController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Create a new controller instance. |
13
|
|
|
*/ |
14
|
|
|
public function __construct() |
15
|
|
|
{ |
16
|
|
|
$this->middleware('auth'); |
17
|
|
|
$this->middleware('can.group'); |
18
|
|
|
$this->middleware('can.student'); |
19
|
|
|
$this->middleware('student.verified'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Confirm joining a group. |
24
|
|
|
* |
25
|
|
|
* @param \App\Judite\Models\Group $group |
26
|
|
|
* |
27
|
|
|
* @return \Illuminate\Http\RedirectResponse |
28
|
|
|
*/ |
29
|
|
|
public function confirm(Group $group) |
30
|
|
|
{ |
31
|
|
|
$student = DB::transaction(function () { |
32
|
|
|
return Auth::user()->student; |
|
|
|
|
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
$this->authorize('reply-group', [$student, $group]); |
36
|
|
|
|
37
|
|
|
DB::transaction(function () use ($student, $group) { |
38
|
|
|
return $student->confirmGroup($group); |
39
|
|
|
}); |
40
|
|
|
flash('The group request was successfully confirmed.')->success(); |
41
|
|
|
|
42
|
|
|
return redirect()->back(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Decline joining a group. |
47
|
|
|
* |
48
|
|
|
* @param \App\Judite\Models\Group $group |
49
|
|
|
* |
50
|
|
|
* @return \Illuminate\Http\RedirectResponse |
51
|
|
|
*/ |
52
|
|
|
public function decline(Group $group) |
53
|
|
|
{ |
54
|
|
|
$student = Auth::user()->student; |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->authorize('reply-group', [$student, $group]); |
57
|
|
|
|
58
|
|
|
DB::transaction(function () use ($student, $group) { |
59
|
|
|
return $student->declineGroup($group); |
60
|
|
|
}); |
61
|
|
|
flash('The group request was successfully declined.')->success(); |
62
|
|
|
|
63
|
|
|
return redirect()->back(); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|