1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\User; |
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
|
8
|
|
|
use App\Http\Requests; |
9
|
|
|
use Bouncer; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class StaffController |
13
|
|
|
* @package App\Http\Controllers |
14
|
|
|
*/ |
15
|
|
|
class StaffController extends Controller |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* StaffController constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$this->middleware('auth'); |
24
|
|
|
$this->middleware('lang'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create new staff member. |
29
|
|
|
* |
30
|
|
|
* @TODO Build up the view |
31
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
32
|
|
|
*/ |
33
|
|
|
public function create() |
34
|
|
|
{ |
35
|
|
|
return view('staff.create'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Store the new member in the database |
40
|
|
|
* |
41
|
|
|
* @TODO: Needs phpunit test. |
42
|
|
|
* @TODO: Build up the controller logic. |
43
|
|
|
* @TODO: Build up the request validator. |
44
|
|
|
* @return \Illuminate\Http\RedirectResponse |
45
|
|
|
*/ |
46
|
|
|
public function store() |
47
|
|
|
{ |
48
|
|
|
return redirect()->back(302); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Update the staff member. |
53
|
|
|
* |
54
|
|
|
* @TODO: Needs phpunit test |
55
|
|
|
* @TODO: Build up the controller. |
56
|
|
|
* @TODO: BUild up the request validator. |
57
|
|
|
* @param int $id The staff member id in the database. |
58
|
|
|
* @return \Illuminate\Http\RedirectResponse |
59
|
|
|
*/ |
60
|
|
|
public function update($id) |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
return redirect()->back(302); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Edit view for a staff member. |
67
|
|
|
* |
68
|
|
|
* @TODO Build up the view. |
69
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
70
|
|
|
*/ |
71
|
|
|
public function edit($id) |
72
|
|
|
{ |
73
|
|
|
$data['query'] = User::find($id); |
|
|
|
|
74
|
|
|
return view('staff.edit', $data); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Display all the staff. |
79
|
|
|
* |
80
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
81
|
|
|
*/ |
82
|
|
|
public function index() |
83
|
|
|
{ |
84
|
|
|
$data['users'] = User::paginate(15); |
|
|
|
|
85
|
|
|
return view('users/index', $data); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Set the user available. |
90
|
|
|
* |
91
|
|
|
* @return \Illuminate\Http\RedirectResponse |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function setAvailable() |
|
|
|
|
94
|
|
|
{ |
95
|
|
|
$user = User::find(auth()->user()->id); |
|
|
|
|
96
|
|
|
Bouncer::retract('unavailable')->from($user); |
97
|
|
|
Bouncer::assign('available')->to($user); |
98
|
|
|
|
99
|
|
|
return redirect()->back(302); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Set the user unavailable. |
104
|
|
|
* |
105
|
|
|
* @return \Illuminate\Http\RedirectResponse |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function setUnavailable() |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
$user = User::find(auth()->user()->id); |
|
|
|
|
110
|
|
|
Bouncer::retract('available')->from($user); |
111
|
|
|
Bouncer::assign('unavailable')->to($user); |
112
|
|
|
|
113
|
|
|
return redirect()->back(302); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Display the profile. |
118
|
|
|
* |
119
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
120
|
|
|
*/ |
121
|
|
|
public function profile() |
122
|
|
|
{ |
123
|
|
|
return view('users/profile'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Destroy or multiple staff members. |
128
|
|
|
* |
129
|
|
|
* @param int $id THe id off the staff member in the database. |
130
|
|
|
* @return \Illuminate\Http\RedirectResponse |
131
|
|
|
*/ |
132
|
|
|
public function destroy($id) |
133
|
|
|
{ |
134
|
|
|
$user = User::find($id); |
135
|
|
|
$user->roles()->sync([]); |
136
|
|
|
|
137
|
|
|
User::destroy($id); |
138
|
|
|
session()->flash('message', 'User deleted'); |
139
|
|
|
|
140
|
|
|
return redirect()->to('/staff'); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.