|
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
|
1 |
|
public function __construct() |
|
12
|
|
|
{ |
|
13
|
1 |
|
} |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Display a listing of all authorized devices |
|
17
|
|
|
* |
|
18
|
|
|
* @return \Illuminate\Http\Response |
|
19
|
|
|
*/ |
|
20
|
1 |
|
public function index(Request $request) |
|
21
|
|
|
{ |
|
22
|
|
|
// fetch devices from the database |
|
23
|
1 |
|
$per_page = $request->per_page ?: 25; |
|
24
|
1 |
|
if ($request->user()->hasGlobalRead()) { |
|
25
|
1 |
|
$devices = Device::paginate($per_page); |
|
26
|
|
|
} else { |
|
27
|
|
|
$devices = User::find($request->user()->user_id)->devices()->paginate($per_page); |
|
28
|
|
|
} |
|
29
|
1 |
|
return $devices; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Show the form for creating a new resource. |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
36
|
|
|
*/ |
|
37
|
|
|
public function create() |
|
38
|
|
|
{ |
|
39
|
|
|
// |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Store a newly created resource in storage. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Illuminate\Http\Request $request |
|
46
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function store(Request $request) |
|
49
|
|
|
{ |
|
50
|
|
|
// |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Display the specified resource. |
|
55
|
|
|
* |
|
56
|
|
|
* @param int $id |
|
57
|
|
|
* @return \Illuminate\Http\Response |
|
58
|
|
|
*/ |
|
59
|
|
|
public function show(Request $request, $id) |
|
60
|
|
|
{ |
|
61
|
|
|
if ($request->user()->hasGlobalRead()) { |
|
62
|
|
|
$device = Device::find($id); |
|
63
|
|
|
} else { |
|
64
|
|
|
$user = User::find($request->user()->user_id); |
|
65
|
|
|
$device = $user->devices()->find($id); |
|
66
|
|
|
} |
|
67
|
|
|
// morph the data as required |
|
68
|
|
|
if ($request->query('displayFormat') == 'link') { |
|
69
|
|
|
return '<a href="'.url('/devices/').$device->deviceId.'">'.$device->hostname.'</a>'; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $device; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Show the form for editing the specified resource. |
|
77
|
|
|
* |
|
78
|
|
|
* @param int $id |
|
79
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public function edit($id) |
|
82
|
|
|
{ |
|
83
|
|
|
// |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Update the specified resource in storage. |
|
88
|
|
|
* |
|
89
|
|
|
* @param \Illuminate\Http\Request $request |
|
90
|
|
|
* @param int $id |
|
91
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
92
|
|
|
*/ |
|
93
|
|
|
public function update(Request $request, $id) |
|
94
|
|
|
{ |
|
95
|
|
|
// |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Remove the specified resource from storage. |
|
100
|
|
|
* |
|
101
|
|
|
* @param int $id |
|
102
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
103
|
|
|
*/ |
|
104
|
|
|
public function destroy($id) |
|
105
|
|
|
{ |
|
106
|
|
|
// |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.