|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Companies\Groups; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Response; |
|
6
|
|
|
use plunner\Group; |
|
7
|
|
|
use plunner\Employee; |
|
8
|
|
|
use plunner\Http\Controllers\Controller; |
|
9
|
|
|
use plunner\Http\Requests\Companies\Groups\EmployeeRequest; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class EmployeesController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var \plunner\Company |
|
16
|
|
|
*/ |
|
17
|
|
|
private $user; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* ExampleController constructor. |
|
21
|
|
|
*/ |
|
22
|
15 |
|
public function __construct() |
|
23
|
|
|
{ |
|
24
|
15 |
|
config(['auth.model' => \plunner\Company::class]); |
|
25
|
15 |
|
config(['jwt.user' => \plunner\Company::class]); |
|
26
|
15 |
|
$this->middleware('jwt.authandrefresh:mode-cn'); |
|
27
|
15 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Display a listing of the resource. |
|
32
|
|
|
* |
|
33
|
|
|
* @param int $groupId |
|
34
|
|
|
* @return \Illuminate\Http\Response |
|
35
|
|
|
*/ |
|
36
|
2 |
|
public function index($groupId) |
|
37
|
|
|
{ |
|
38
|
|
|
// |
|
39
|
2 |
|
$group = Group::findOrFail($groupId); |
|
40
|
2 |
|
$this->authorize($group); |
|
41
|
2 |
|
return $group->employees; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Store a newly created resource in storage. |
|
46
|
|
|
* |
|
47
|
|
|
* @param EmployeeRequest $request |
|
48
|
|
|
* @param int $groupId |
|
49
|
|
|
* @return \Illuminate\Http\Response |
|
50
|
|
|
*/ |
|
51
|
4 |
|
public function store(EmployeeRequest $request, $groupId) |
|
52
|
|
|
{ |
|
53
|
|
|
// |
|
54
|
4 |
|
$group = Group::findOrFail($groupId); |
|
55
|
4 |
|
$this->authorize($group); |
|
56
|
2 |
|
$id = $request->all()['id']; |
|
57
|
2 |
|
$group->employees()->attach($id); |
|
58
|
2 |
|
return $group->employees; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Remove the specified resource from storage. |
|
63
|
|
|
* |
|
64
|
|
|
* @param int $groupId |
|
65
|
|
|
* @param int $employeeId |
|
66
|
|
|
* @return \Illuminate\Http\Response |
|
67
|
|
|
*/ |
|
68
|
7 |
|
public function destroy($groupId, $employeeId) |
|
69
|
|
|
{ |
|
70
|
|
|
// |
|
71
|
7 |
|
$employee = Employee::findOrFail($employeeId); |
|
72
|
7 |
|
$this->authorize($employee); |
|
73
|
3 |
|
$group = Group::findOrFail($groupId); |
|
74
|
3 |
|
if(!$employee->belongsToGroup($group)) |
|
75
|
3 |
|
return Response::json(['error' => 'employId <> groupId'],404); |
|
76
|
2 |
|
$employee->groups()->detach($groupId); |
|
77
|
2 |
|
return $group->employees; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.