1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Companies\Employees; |
4
|
|
|
|
5
|
|
|
use plunner\Company; |
6
|
|
|
use plunner\Employee; |
7
|
|
|
use plunner\Http\Controllers\Controller; |
8
|
|
|
use plunner\Http\Requests\Companies\Employees\EmployeeRequest; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class EmployeesController |
12
|
|
|
* @package plunner\Http\Controllers\Companies\Employees |
13
|
|
|
* @author Claudio Cardinale <[email protected]> |
14
|
|
|
* @copyright 2015 Claudio Cardinale |
15
|
|
|
* @version 1.0.0 |
16
|
|
|
*/ |
17
|
|
|
class EmployeesController extends Controller |
18
|
|
|
{ |
19
|
24 |
|
public function __construct() |
20
|
|
|
{ |
21
|
24 |
|
config(['auth.model' => \plunner\Company::class]); |
22
|
24 |
|
config(['jwt.user' => \plunner\Company::class]); |
23
|
24 |
|
$this->middleware('jwt.authandrefresh:mode-cn'); |
24
|
24 |
|
} |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Display a listing of the resource. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Http\Response |
31
|
|
|
*/ |
32
|
3 |
|
public function index() |
33
|
|
|
{ |
34
|
|
|
// |
35
|
|
|
/** |
36
|
|
|
* @var $company Company |
37
|
|
|
*/ |
38
|
3 |
|
$company = \Auth::user(); |
39
|
3 |
|
return $company->employees()->with('groups.planner')->get(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Store a newly created resource in storage. |
44
|
|
|
* |
45
|
|
|
* @param EmployeeRequest $request |
46
|
|
|
* @return \Illuminate\Http\Response |
47
|
|
|
*/ |
48
|
6 |
|
public function store(EmployeeRequest $request) |
49
|
|
|
{ |
50
|
|
|
// |
51
|
6 |
|
$company = \Auth::user(); |
52
|
6 |
|
$input = $request->all(); |
53
|
6 |
|
if (isset($input['password'])) |
54
|
6 |
|
$input['password'] = bcrypt($input['password']); |
55
|
6 |
|
$employee = $company->employees()->create($input); |
56
|
6 |
|
return $employee; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Display the specified resource. |
61
|
|
|
* |
62
|
|
|
* @param int $id |
63
|
|
|
* @return \Illuminate\Http\Response |
64
|
|
|
*/ |
65
|
6 |
|
public function show($id) |
66
|
|
|
{ |
67
|
|
|
// |
68
|
6 |
|
$employee = Employee::with('groups.planner')->findOrFail($id); |
69
|
6 |
|
$this->authorize($employee); |
70
|
6 |
|
return $employee; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Update the specified resource in storage. |
75
|
|
|
* |
76
|
|
|
* @param EmployeeRequest $request |
77
|
|
|
* @param int $id |
78
|
|
|
* @return \Illuminate\Http\Response |
79
|
|
|
*/ |
80
|
3 |
|
public function update(EmployeeRequest $request, $id) |
81
|
|
|
{ |
82
|
|
|
// |
83
|
3 |
|
$employee = Employee::findOrFail($id); |
84
|
3 |
|
$this->authorize($employee); |
85
|
3 |
|
$input = $request->all(); |
86
|
3 |
|
if (isset($input['password'])) |
87
|
3 |
|
$input['password'] = bcrypt($input['password']); |
88
|
3 |
|
$employee->update($input); |
89
|
3 |
|
return $employee; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Remove the specified resource from storage. |
94
|
|
|
* |
95
|
|
|
* @param int $id |
96
|
|
|
* @return \Illuminate\Http\Response |
97
|
|
|
*/ |
98
|
6 |
|
public function destroy($id) |
99
|
|
|
{ |
100
|
|
|
// |
101
|
6 |
|
$employee = Employee::findOrFail($id); |
102
|
6 |
|
$this->authorize($employee); |
103
|
3 |
|
$employee->delete(); |
104
|
3 |
|
return $employee; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|