|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace jeremykenedy\LaravelBlocker\App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use Illuminate\Http\Response; |
|
7
|
|
|
use jeremykenedy\LaravelBlocker\App\Http\Requests\SearchBlockerRequest; |
|
8
|
|
|
use jeremykenedy\LaravelBlocker\App\Models\BlockedItem; |
|
9
|
|
|
|
|
10
|
|
|
class LaravelBlockerDeletedController extends LaravelBlockerController |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Get Soft Deleted BlockedItem. |
|
14
|
|
|
* |
|
15
|
|
|
* @param int $id |
|
16
|
|
|
* |
|
17
|
|
|
* @return \Illuminate\Http\Response |
|
18
|
|
|
*/ |
|
19
|
|
|
public static function getDeletedBlockedItem($id) |
|
20
|
|
|
{ |
|
21
|
|
|
$item = BlockedItem::onlyTrashed()->where('id', $id)->get(); |
|
22
|
|
|
if (count($item) != 1) { |
|
23
|
|
|
return abort(redirect('blocker-deleted') |
|
|
|
|
|
|
24
|
|
|
->with('error', trans('laravelblocker::laravelblocker.errors.errorBlockerNotFound'))); |
|
|
|
|
|
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return $item[0]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Show the laravel ip blocker deleted dashboard. |
|
32
|
|
|
* |
|
33
|
|
|
* @return \Illuminate\Http\Response |
|
34
|
|
|
*/ |
|
35
|
|
|
public function index() |
|
36
|
|
|
{ |
|
37
|
|
|
if (config('laravelblocker.blockerPaginationEnabled')) { |
|
|
|
|
|
|
38
|
|
|
$blocked = BlockedItem::onlyTrashed()->paginate(config('laravelblocker.blockerPaginationPerPage')); |
|
39
|
|
|
} else { |
|
40
|
|
|
$blocked = BlockedItem::onlyTrashed()->get(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return view('laravelblocker::laravelblocker.deleted.index', compact('blocked')); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Display the specified resource. |
|
48
|
|
|
* |
|
49
|
|
|
* @param int $id |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Http\Response |
|
52
|
|
|
*/ |
|
53
|
|
|
public function show($id) |
|
54
|
|
|
{ |
|
55
|
|
|
$item = self::getDeletedBlockedItem($id); |
|
56
|
|
|
$typeDeleted = 'deleted'; |
|
57
|
|
|
|
|
58
|
|
|
return view('laravelblocker::laravelblocker.show', compact('item', 'typeDeleted')); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Update the specified resource in storage. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \Illuminate\Http\Request $request |
|
65
|
|
|
* @param int $id |
|
66
|
|
|
* |
|
67
|
|
|
* @return \Illuminate\Http\Response |
|
68
|
|
|
*/ |
|
69
|
|
|
public function restoreBlockedItem(Request $request, $id) |
|
70
|
|
|
{ |
|
71
|
|
|
$item = self::getDeletedBlockedItem($id); |
|
72
|
|
|
$item->restore(); |
|
73
|
|
|
|
|
74
|
|
|
return redirect('blocker') |
|
|
|
|
|
|
75
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.successRestoredItem')); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Restore all the specified resource from soft deleted storage. |
|
80
|
|
|
* |
|
81
|
|
|
* @param Request $request |
|
82
|
|
|
* |
|
83
|
|
|
* @return \Illuminate\Http\Response |
|
84
|
|
|
*/ |
|
85
|
|
|
public function restoreAllBlockedItems(Request $request) |
|
86
|
|
|
{ |
|
87
|
|
|
$items = BlockedItem::onlyTrashed()->get(); |
|
88
|
|
|
foreach ($items as $item) { |
|
89
|
|
|
$item->restore(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return redirect('blocker') |
|
|
|
|
|
|
93
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.successRestoredAllItems')); |
|
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Remove the specified resource from storage. |
|
98
|
|
|
* |
|
99
|
|
|
* @param int $id |
|
100
|
|
|
* |
|
101
|
|
|
* @return \Illuminate\Http\Response |
|
102
|
|
|
*/ |
|
103
|
|
|
public function destroy($id) |
|
104
|
|
|
{ |
|
105
|
|
|
$item = self::getDeletedBlockedItem($id); |
|
106
|
|
|
$item->forceDelete(); |
|
107
|
|
|
|
|
108
|
|
|
return redirect('blocker-deleted') |
|
|
|
|
|
|
109
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.successDestroyedItem')); |
|
|
|
|
|
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Destroy all the specified resource from storage. |
|
114
|
|
|
* |
|
115
|
|
|
* @param Request $request |
|
116
|
|
|
* |
|
117
|
|
|
* @return \Illuminate\Http\Response |
|
118
|
|
|
*/ |
|
119
|
|
|
public function destroyAllItems(Request $request) |
|
120
|
|
|
{ |
|
121
|
|
|
$items = BlockedItem::onlyTrashed()->get(); |
|
122
|
|
|
|
|
123
|
|
|
foreach ($items as $item) { |
|
124
|
|
|
$item->forceDelete(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return redirect('blocker') |
|
|
|
|
|
|
128
|
|
|
->with('success', trans('laravelblocker::laravelblocker.messages.successDestroyedAllItems')); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Method to search the deleted blocked items. |
|
133
|
|
|
* |
|
134
|
|
|
* @param SearchBlockerRequest $request |
|
135
|
|
|
* |
|
136
|
|
|
* @return \Illuminate\Http\Response |
|
137
|
|
|
*/ |
|
138
|
|
|
public function search(SearchBlockerRequest $request) |
|
139
|
|
|
{ |
|
140
|
|
|
$searchTerm = $request->validated()['blocked_search_box']; |
|
141
|
|
|
$results = BlockedItem::onlyTrashed()->where('id', 'like', $searchTerm.'%')->onlyTrashed() |
|
142
|
|
|
->orWhere('typeId', 'like', $searchTerm.'%')->onlyTrashed() |
|
143
|
|
|
->orWhere('value', 'like', $searchTerm.'%')->onlyTrashed() |
|
144
|
|
|
->orWhere('note', 'like', $searchTerm.'%')->onlyTrashed() |
|
145
|
|
|
->orWhere('userId', 'like', $searchTerm.'%')->onlyTrashed() |
|
146
|
|
|
->get(); |
|
147
|
|
|
|
|
148
|
|
|
$results->map(function ($item) { |
|
149
|
|
|
$item['type'] = $item->blockedType->slug; |
|
150
|
|
|
|
|
151
|
|
|
return $item; |
|
152
|
|
|
}); |
|
153
|
|
|
|
|
154
|
|
|
return response()->json([ |
|
|
|
|
|
|
155
|
|
|
json_encode($results), |
|
156
|
|
|
], Response::HTTP_OK); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|