|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Api\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Models\Device; |
|
6
|
|
|
use App\Models\User; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
|
|
9
|
|
|
class DeviceController extends Controller |
|
10
|
|
|
{ |
|
11
|
2 |
|
public function __construct() { |
|
12
|
|
|
|
|
13
|
2 |
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Display a listing of all authorized devices |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Illuminate\Http\Response |
|
19
|
|
|
*/ |
|
20
|
2 |
|
public function index(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
// fetch devices from the database |
|
23
|
2 |
|
if ($request->user()->hasGlobalRead()) { |
|
24
|
1 |
|
$devices = Device::all(); |
|
25
|
1 |
|
} |
|
26
|
|
|
else { |
|
27
|
2 |
|
$devices = User::find($request->user()->user_id)->devices()->get(); |
|
28
|
|
|
} |
|
29
|
|
|
// morph the data as required |
|
30
|
2 |
|
if ($request->query('displayFormat') == 'human') { |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
2 |
|
return $devices; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Show the form for creating a new resource. |
|
38
|
|
|
* |
|
39
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
40
|
|
|
*/ |
|
41
|
|
|
public function create() |
|
42
|
|
|
{ |
|
43
|
|
|
// |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Store a newly created resource in storage. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Illuminate\Http\Request $request |
|
50
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
51
|
|
|
*/ |
|
52
|
|
|
public function store(Request $request) |
|
|
|
|
|
|
53
|
|
|
{ |
|
54
|
|
|
// |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Display the specified resource. |
|
59
|
|
|
* |
|
60
|
|
|
* @param int $id |
|
61
|
|
|
* @return \Illuminate\Http\Response |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function show(Request $request, $id) |
|
64
|
|
|
{ |
|
65
|
|
|
if ($request->user()->hasGlobalRead()) { |
|
66
|
|
|
$device = Device::find($id); |
|
67
|
|
|
} |
|
68
|
|
|
else { |
|
69
|
|
|
$user = User::find($request->user()->user_id); |
|
70
|
|
|
$device = $user->devices()->find($id); |
|
71
|
|
|
} |
|
72
|
|
|
// morph the data as required |
|
73
|
|
|
if ($request->query('displayFormat') == 'link') { |
|
74
|
|
|
return '<a href="'.url('/devices/').$device->deviceId.'">'.$device->hostname.'</a>'; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
return $device; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Show the form for editing the specified resource. |
|
82
|
|
|
* |
|
83
|
|
|
* @param int $id |
|
84
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function edit($id) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
// |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Update the specified resource in storage. |
|
93
|
|
|
* |
|
94
|
|
|
* @param \Illuminate\Http\Request $request |
|
95
|
|
|
* @param int $id |
|
96
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
97
|
|
|
*/ |
|
98
|
|
|
public function update(Request $request, $id) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
// |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Remove the specified resource from storage. |
|
105
|
|
|
* |
|
106
|
|
|
* @param int $id |
|
107
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
108
|
|
|
*/ |
|
109
|
|
|
public function destroy($id) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
// |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
This check looks for the bodies of
ifstatements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
ifbodies can be removed. If you have an empty if but statements in theelsebranch, consider inverting the condition.could be turned into
This is much more concise to read.