|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* UserPortController.php |
|
4
|
|
|
* |
|
5
|
|
|
* Controls the user port relationship |
|
6
|
|
|
* |
|
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
* it under the terms of the GNU General Public License as published by |
|
9
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
* (at your option) any later version. |
|
11
|
|
|
* |
|
12
|
|
|
* This program is distributed in the hope that it will be useful, |
|
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
|
15
|
|
|
* GNU General Public License for more details. |
|
16
|
|
|
* |
|
17
|
|
|
* You should have received a copy of the GNU General Public License |
|
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
* |
|
20
|
|
|
* @package LibreNMS |
|
21
|
|
|
* @link http://librenms.org |
|
22
|
|
|
* @copyright 2016 Tony Murray |
|
23
|
|
|
* @author Tony Murray <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace App\Http\Controllers; |
|
27
|
|
|
|
|
28
|
|
|
use App\Http\Requests\AdminOnlyRequest; |
|
29
|
|
|
use App\Models\Port; |
|
30
|
|
|
use App\Models\User; |
|
31
|
|
|
|
|
32
|
|
|
class UserPortController extends Controller |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @param AdminOnlyRequest $request |
|
36
|
|
|
* @param $user_id |
|
37
|
|
|
* @return mixed |
|
38
|
|
|
*/ |
|
39
|
|
|
public function create(AdminOnlyRequest $request, $user_id) |
|
40
|
|
|
{ |
|
41
|
|
|
$user = User::with('ports')->find($user_id); |
|
42
|
|
|
return view('users.ports-create')->withUser($user); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param AdminOnlyRequest $request |
|
47
|
|
|
* @param $user_id |
|
48
|
|
|
* @param $port_id |
|
49
|
|
|
* @return mixed |
|
50
|
|
|
*/ |
|
51
|
|
|
public function store(AdminOnlyRequest $request, $user_id) |
|
52
|
|
|
{ |
|
53
|
|
|
$user = User::find($user_id); |
|
54
|
|
|
|
|
55
|
|
|
$port_ids = $request->input('ports'); |
|
56
|
|
|
|
|
57
|
|
|
if (!is_array($port_ids) || count($port_ids) == 0) { |
|
58
|
|
|
return redirect()->back(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
foreach ($port_ids as $port_id) { |
|
62
|
|
|
$port = Port::find($port_id); |
|
63
|
|
|
$user->ports()->attach($port); |
|
64
|
|
|
} |
|
65
|
|
|
return redirect()->back()->with(['type' => 'success', 'message' => trans('user.text.portsadded')]); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param AdminOnlyRequest $request |
|
70
|
|
|
* @param $user_id |
|
71
|
|
|
* @param $port_id |
|
72
|
|
|
* @return mixed |
|
73
|
|
|
*/ |
|
74
|
|
|
public function destroy(AdminOnlyRequest $request, $user_id, $port_id) |
|
75
|
|
|
{ |
|
76
|
|
|
$user = User::find($user_id); |
|
77
|
|
|
$port = Port::find($port_id); |
|
78
|
|
|
$user->ports()->detach($port); |
|
79
|
|
|
return redirect()->back()->with(['type' => 'success', 'message' => trans('user.text.portremoved', ['label' => $port->getLabel()])]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|