|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\Http\Requests; |
|
7
|
|
|
use App\Departments; |
|
8
|
|
|
use App\DepartmentMembers; |
|
9
|
|
|
use Mail; |
|
10
|
|
|
use App\User; |
|
11
|
|
|
use App\Http\Controllers\Controller; |
|
12
|
|
|
|
|
13
|
|
|
class DepartmentsController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* DepartmentsController Constructor. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->middleware('auth'); |
|
21
|
|
|
$this->middleware('lang'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get the departments index. |
|
26
|
|
|
* |
|
27
|
|
|
* @return view |
|
28
|
|
|
*/ |
|
29
|
|
|
public function index() |
|
30
|
|
|
{ |
|
31
|
|
|
$departments = Departments::orderBy('department_name', 'asc')->with('managers')->paginate(10); |
|
32
|
|
|
return view('departments/list', ['departments' => $departments]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* This is nothing for in the controller. |
|
37
|
|
|
* If you want to test this. You should create a phpunit function for the relation.$_COOKIE |
|
38
|
|
|
* |
|
39
|
|
|
* TODO: Create phpunit testing function. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function relationtest() |
|
42
|
|
|
{ |
|
43
|
|
|
$departments = DepartmentMembers::All(); |
|
44
|
|
|
return $departments; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function create() |
|
48
|
|
|
{ |
|
49
|
|
|
$managers = User::all(); |
|
50
|
|
|
return view('departments/create', ['managers' => $managers]); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Store a newly created resource in storage. |
|
55
|
|
|
* |
|
56
|
|
|
* @param Requests\DepartmentsValidator|Request $request |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function store(Requests\DepartmentsValidator $request) |
|
60
|
|
|
{ |
|
61
|
|
|
// TODO: Check for mass assign - SQL queries. |
|
62
|
|
|
|
|
63
|
|
|
$departments = new Departments; |
|
64
|
|
|
$departments->department_name = $request->get('department_name'); |
|
65
|
|
|
$departments->department_manager = $request->get('department_manager'); |
|
66
|
|
|
$departments->department_description = $request->get('department_description'); |
|
67
|
|
|
$departments->save(); |
|
68
|
|
|
|
|
69
|
|
|
$department_id = $departments->id; |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$manager = new DepartmentMembers; |
|
72
|
|
|
$manager->departmentid = $department_id; |
|
73
|
|
|
$manager->userid = $request->get('department_manager'); |
|
74
|
|
|
$manager->save(); |
|
75
|
|
|
|
|
76
|
|
|
\Session::flash('message', "New department has been saved"); |
|
77
|
|
|
return redirect('staff/departments'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Display the specified resource. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $id |
|
84
|
|
|
* @return \Illuminate\Http\Response |
|
85
|
|
|
*/ |
|
86
|
|
|
public function show($id) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
// |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Show the form for editing the specified resource. |
|
93
|
|
|
* |
|
94
|
|
|
* @param int $id |
|
95
|
|
|
* @return \Illuminate\Http\Response |
|
96
|
|
|
*/ |
|
97
|
|
|
public function edit($id) |
|
|
|
|
|
|
98
|
|
|
{ |
|
99
|
|
|
return view('departments/edit'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Update the specified resource in storage. |
|
104
|
|
|
* |
|
105
|
|
|
* @param \Illuminate\Http\Request $request |
|
106
|
|
|
* @param int $id |
|
107
|
|
|
* @return \Illuminate\Http\Response |
|
108
|
|
|
*/ |
|
109
|
|
|
public function update(Request $request, $id) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
// |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Search a department in the database. |
|
116
|
|
|
* |
|
117
|
|
|
* @param Request $request |
|
118
|
|
|
* @return \Illuminate\Http\Response |
|
119
|
|
|
*/ |
|
120
|
|
|
public function search(Request $request) |
|
121
|
|
|
{ |
|
122
|
|
|
$term = $request->get('name'); |
|
123
|
|
|
|
|
124
|
|
|
if (empty($term)) { |
|
125
|
|
|
return redirect('staff/departments', 302); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
$data['departments'] = Departments::where('department_name', 'LIKE', "%$term%") |
|
|
|
|
|
|
129
|
|
|
->orderBy('department_name', 'asc') |
|
130
|
|
|
->with('managers') |
|
131
|
|
|
->paginate(10); |
|
132
|
|
|
|
|
133
|
|
|
return view('departments/list', $data); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Remove the specified resource from storage. |
|
138
|
|
|
* |
|
139
|
|
|
* @param Request $request |
|
140
|
|
|
* @return \Illuminate\Http\Response |
|
141
|
|
|
*/ |
|
142
|
|
|
public function destroy(Request $request) |
|
143
|
|
|
{ |
|
144
|
|
|
$query = Departments::destroy($request->get('department_id')); |
|
145
|
|
|
session()->flash('message', "$query department(s) deleted"); |
|
146
|
|
|
|
|
147
|
|
|
return redirect()->back(302); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.