|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use App\ProxyListItem; |
|
7
|
|
|
|
|
8
|
|
|
class ProxyListItemController extends Controller |
|
9
|
|
|
{ |
|
10
|
|
|
use SearchTrait; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Create a new controller instance. |
|
14
|
|
|
* |
|
15
|
|
|
* @return void |
|
|
|
|
|
|
16
|
|
|
*/ |
|
17
|
|
|
public function __construct() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->middleware('auth'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
View Code Duplication |
protected function showList(Request $request, $type) |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
$items = ProxyListItem::where('type', $type)->orderBy('value', 'asc'); |
|
25
|
|
|
|
|
26
|
|
|
$results = $this->search($items, 'value', $request->input('search')); |
|
27
|
|
|
|
|
28
|
|
|
if (false === is_null($results)) { |
|
29
|
|
|
$request->session()->flash( |
|
30
|
|
|
'results', |
|
31
|
|
|
trans_choice( |
|
32
|
|
|
'proxylist.message.search', |
|
33
|
|
|
$results, |
|
34
|
|
|
['number' => $results] |
|
35
|
|
|
) |
|
36
|
|
|
); |
|
37
|
|
|
$request->session()->flash('search', $request->input('search')); |
|
38
|
|
|
$request->session()->flash('type', $request->input('type')); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return view("proxy/proxylist", ['items' => $items->paginate(20), 'type' => $type]); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function addItem(Request $request, $type) |
|
45
|
|
|
{ |
|
46
|
|
|
$urlRule = ($type == 'url') ? '|url' : ''; |
|
47
|
|
|
$this->validate($request, [ |
|
48
|
|
|
'value' => "required|unique:proxylistitems,value{$urlRule}", |
|
49
|
|
|
]); |
|
50
|
|
|
|
|
51
|
|
|
if (false === empty($request->id)) { |
|
52
|
|
|
return $this->updateItem($request, $type, $request->id); |
|
53
|
|
|
} else { |
|
54
|
|
|
$item = new ProxyListItem; |
|
55
|
|
|
$item->value = $request->value; |
|
|
|
|
|
|
56
|
|
|
$item->type = $type; |
|
|
|
|
|
|
57
|
|
|
$item->whitelist = true; |
|
|
|
|
|
|
58
|
|
|
$item->created_by = $request->user()->id; |
|
|
|
|
|
|
59
|
|
|
$item->save(); |
|
60
|
|
|
return redirect()->back()->with( |
|
61
|
|
|
'status', |
|
62
|
|
|
trans('proxylist.message.add', ['type' => trans_choice("proxylist.{$type}", 1)]) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function updateItem(Request $request, $type, $id) |
|
68
|
|
|
{ |
|
69
|
|
|
$urlRule = ($type == 'url') ? '|url' : ''; |
|
70
|
|
|
$this->validate($request, [ |
|
71
|
|
|
'value' => "required|unique:proxylistitems,value{$urlRule}", |
|
72
|
|
|
]); |
|
73
|
|
|
|
|
74
|
|
|
$item = ProxyListItem::findOrFail($id); |
|
75
|
|
|
$item->value = $request->value; |
|
76
|
|
|
$item->update(); |
|
77
|
|
|
return redirect()->back()->with( |
|
78
|
|
|
'status', |
|
79
|
|
|
trans('proxylist.message.update', ['type' => trans_choice("proxylist.{$type}", 1)]) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function removeItem($type, $id) |
|
84
|
|
|
{ |
|
85
|
|
|
$item = ProxyListItem::findOrFail($id); |
|
86
|
|
|
$value = $item->value; |
|
87
|
|
|
$item->delete(); |
|
88
|
|
|
return redirect()->back()->with( |
|
89
|
|
|
'status', |
|
90
|
|
|
trans( |
|
91
|
|
|
'proxylist.message.delete', |
|
92
|
|
|
[ |
|
93
|
|
|
'type' => trans_choice("proxylist.{$type}", 1), |
|
94
|
|
|
'value' => $value, |
|
95
|
|
|
] |
|
96
|
|
|
) |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function clearList($type) |
|
101
|
|
|
{ |
|
102
|
|
|
$items = ProxyListItem::where('type', $type); |
|
103
|
|
|
$items->delete(); |
|
104
|
|
|
return redirect()->back()->with( |
|
105
|
|
|
'status', |
|
106
|
|
|
trans('proxylist.message.drop', ['type' => trans_choice("proxylist.{$type}", 1)]) |
|
107
|
|
|
); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.