1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace jeremykenedy\LaravelBlocker\App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
6
|
|
|
use Illuminate\Http\Response; |
7
|
|
|
use jeremykenedy\LaravelBlocker\App\Http\Requests\SearchBlockerRequest; |
8
|
|
|
use jeremykenedy\LaravelBlocker\App\Http\Requests\StoreBlockerRequest; |
9
|
|
|
use jeremykenedy\LaravelBlocker\App\Http\Requests\UpdateBlockerRequest; |
10
|
|
|
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem; |
11
|
|
|
use jeremykenedy\LaravelBlocker\App\Models\BlockedType; |
12
|
|
|
|
13
|
|
|
class LaravelBlockerController extends Controller |
14
|
|
|
{ |
15
|
|
|
private $_authEnabled; |
16
|
|
|
private $_rolesEnabled; |
17
|
|
|
private $_rolesMiddlware; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Create a new controller instance. |
21
|
|
|
* |
22
|
|
|
* @return void |
23
|
|
|
*/ |
24
|
|
|
public function __construct() |
25
|
|
|
{ |
26
|
|
|
$this->_authEnabled = config('laravelblocker.authEnabled'); |
|
|
|
|
27
|
|
|
$this->_rolesEnabled = config('laravelblocker.rolesEnabled'); |
28
|
|
|
$this->_rolesMiddlware = config('laravelblocker.rolesMiddlware'); |
29
|
|
|
|
30
|
|
|
if ($this->_authEnabled) { |
31
|
|
|
$this->middleware('auth'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if ($this->_rolesEnabled) { |
35
|
|
|
$this->middleware($this->_rolesMiddlware); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Show the laravel ip email blocker dashboard. |
41
|
|
|
* |
42
|
|
|
* @return \Illuminate\Http\Response |
43
|
|
|
*/ |
44
|
|
|
public function index() |
45
|
|
|
{ |
46
|
|
|
if (config('laravelblocker.blockerPaginationEnabled')) { |
|
|
|
|
47
|
|
|
$blocked = BlockedItem::paginate(config('laravelblocker.blockerPaginationPerPage')); |
48
|
|
|
} else { |
49
|
|
|
$blocked = BlockedItem::all(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$deletedBlockedItems = BlockedItem::onlyTrashed(); |
53
|
|
|
|
54
|
|
|
return view('laravelblocker::laravelblocker.index', compact('blocked', 'deletedBlockedItems')); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Show the form for creating a new resource. |
59
|
|
|
* |
60
|
|
|
* @return \Illuminate\Http\Response |
61
|
|
|
*/ |
62
|
|
|
public function create() |
63
|
|
|
{ |
64
|
|
|
$blockedTypes = BlockedType::all(); |
65
|
|
|
$users = config('laravelblocker.defaultUserModel')::all(); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return view('laravelblocker::laravelblocker.create', compact('blockedTypes', 'users')); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Store a newly created resource in storage. |
72
|
|
|
* |
73
|
|
|
* @param StoreBlockerRequest $request |
74
|
|
|
* |
75
|
|
|
* @return \Illuminate\Http\Response |
76
|
|
|
*/ |
77
|
|
|
public function store(StoreBlockerRequest $request) |
78
|
|
|
{ |
79
|
|
|
BlockedItem::create($request->blockedFillData()); |
80
|
|
|
|
81
|
|
|
return redirect('blocker') |
|
|
|
|
82
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.blocked-creation-success')); |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Display the specified resource. |
87
|
|
|
* |
88
|
|
|
* @param int $id |
89
|
|
|
* |
90
|
|
|
* @return \Illuminate\Http\Response |
91
|
|
|
*/ |
92
|
|
|
public function show($id) |
93
|
|
|
{ |
94
|
|
|
$item = BlockedItem::findOrFail($id); |
95
|
|
|
|
96
|
|
|
return view('laravelblocker::laravelblocker.show', compact('item')); |
|
|
|
|
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Display the specified resource. |
101
|
|
|
* |
102
|
|
|
* @param int $id |
103
|
|
|
* |
104
|
|
|
* @return \Illuminate\Http\Response |
105
|
|
|
*/ |
106
|
|
|
public function edit($id) |
107
|
|
|
{ |
108
|
|
|
$blockedTypes = BlockedType::all(); |
109
|
|
|
$users = config('laravelblocker.defaultUserModel')::all(); |
|
|
|
|
110
|
|
|
$item = BlockedItem::findOrFail($id); |
111
|
|
|
|
112
|
|
|
return view('laravelblocker::laravelblocker.edit', compact('blockedTypes', 'users', 'item')); |
|
|
|
|
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Update the specified resource in storage. |
117
|
|
|
* |
118
|
|
|
* @param UpdateBlockerRequest $request |
119
|
|
|
* @param int $id |
120
|
|
|
* |
121
|
|
|
* @return \Illuminate\Http\Response |
122
|
|
|
*/ |
123
|
|
|
public function update(UpdateBlockerRequest $request, $id) |
124
|
|
|
{ |
125
|
|
|
$item = BlockedItem::findOrFail($id); |
126
|
|
|
$item->fill($request->blockedFillData()); |
127
|
|
|
$item->save(); |
128
|
|
|
|
129
|
|
|
return redirect() |
|
|
|
|
130
|
|
|
->back() |
131
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.update-success')); |
|
|
|
|
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Remove the specified resource from storage. |
136
|
|
|
* |
137
|
|
|
* @param int $id |
138
|
|
|
* |
139
|
|
|
* @return \Illuminate\Http\Response |
140
|
|
|
*/ |
141
|
|
|
public function destroy($id) |
142
|
|
|
{ |
143
|
|
|
$blockedItem = BlockedItem::findOrFail($id); |
144
|
|
|
$blockedItem->delete(); |
145
|
|
|
|
146
|
|
|
return redirect('blocker') |
|
|
|
|
147
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.delete-success')); |
|
|
|
|
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Method to search the blocked items. |
152
|
|
|
* |
153
|
|
|
* @param SearchBlockerRequest $request |
154
|
|
|
* |
155
|
|
|
* @return \Illuminate\Http\Response |
156
|
|
|
*/ |
157
|
|
|
public function search(SearchBlockerRequest $request) |
158
|
|
|
{ |
159
|
|
|
$searchTerm = $request->validated()['blocked_search_box']; |
160
|
|
|
$results = BlockedItem::where('id', 'like', $searchTerm.'%') |
161
|
|
|
->orWhere('typeId', 'like', $searchTerm.'%') |
162
|
|
|
->orWhere('value', 'like', $searchTerm.'%') |
163
|
|
|
->orWhere('note', 'like', $searchTerm.'%') |
164
|
|
|
->orWhere('userId', 'like', $searchTerm.'%') |
165
|
|
|
->get(); |
166
|
|
|
|
167
|
|
|
$results->map(function ($item) { |
168
|
|
|
$item['type'] = $item->blockedType->slug; |
169
|
|
|
|
170
|
|
|
return $item; |
171
|
|
|
}); |
172
|
|
|
|
173
|
|
|
return response()->json([ |
|
|
|
|
174
|
|
|
json_encode($results), |
175
|
|
|
], Response::HTTP_OK); |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths