1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Encore\Admin\Controllers; |
4
|
|
|
|
5
|
|
|
use Encore\Admin\Auth\Database\Administrator; |
6
|
|
|
use Encore\Admin\Auth\Database\OperationLog; |
7
|
|
|
use Encore\Admin\Grid; |
8
|
|
|
use Encore\Admin\Layout\Content; |
9
|
|
|
use Illuminate\Routing\Controller; |
10
|
|
|
|
11
|
|
|
class LogController extends Controller |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* Index interface. |
15
|
|
|
* |
16
|
|
|
* @param Content $content |
17
|
|
|
* @return Content |
18
|
|
|
*/ |
19
|
|
|
public function index(Content $content) |
20
|
|
|
{ |
21
|
|
|
return $content |
22
|
|
|
->header(trans('admin.operation_log')) |
23
|
|
|
->description(trans('admin.list')) |
24
|
|
|
->body($this->grid()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return Grid |
29
|
|
|
*/ |
30
|
|
|
protected function grid() |
31
|
|
|
{ |
32
|
|
|
$grid = new Grid(new OperationLog); |
33
|
|
|
|
34
|
|
|
$grid->model()->orderBy('id', 'DESC'); |
|
|
|
|
35
|
|
|
|
36
|
|
|
$grid->id('ID')->sortable(); |
|
|
|
|
37
|
|
|
$grid->user()->name('User'); |
|
|
|
|
38
|
|
|
$grid->method()->display(function ($method) { |
|
|
|
|
39
|
|
|
$color = array_get(OperationLog::$methodColors, $method, 'grey'); |
40
|
|
|
|
41
|
|
|
return "<span class=\"badge bg-$color\">$method</span>"; |
42
|
|
|
}); |
43
|
|
|
$grid->path()->label('info'); |
|
|
|
|
44
|
|
|
$grid->ip()->label('primary'); |
|
|
|
|
45
|
|
|
$grid->input()->display(function ($input) { |
|
|
|
|
46
|
|
|
$input = json_decode($input, true); |
47
|
|
|
$input = array_except($input, ['_pjax', '_token', '_method', '_previous_']); |
48
|
|
|
if (empty($input)) { |
49
|
|
|
return '<code>{}</code>'; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return '<pre>'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</pre>'; |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
$grid->created_at(trans('admin.created_at')); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) { |
58
|
|
|
$actions->disableEdit(); |
59
|
|
|
$actions->disableView(); |
60
|
|
|
}); |
61
|
|
|
|
62
|
|
|
$grid->disableCreation(); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$grid->filter(function ($filter) { |
65
|
|
|
$filter->equal('user_id', 'User')->select(Administrator::all()->pluck('name', 'id')); |
66
|
|
|
$filter->equal('method')->select(array_combine(OperationLog::$methods, OperationLog::$methods)); |
67
|
|
|
$filter->like('path'); |
68
|
|
|
$filter->equal('ip'); |
69
|
|
|
}); |
70
|
|
|
|
71
|
|
|
return $grid; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param mixed $id |
76
|
|
|
* @return \Illuminate\Http\JsonResponse |
77
|
|
|
*/ |
78
|
|
|
public function destroy($id) |
79
|
|
|
{ |
80
|
|
|
$ids = explode(',', $id); |
81
|
|
|
|
82
|
|
|
if (OperationLog::destroy(array_filter($ids))) { |
83
|
|
|
$data = [ |
84
|
|
|
'status' => true, |
85
|
|
|
'message' => trans('admin.delete_succeeded'), |
86
|
|
|
]; |
87
|
|
|
} else { |
88
|
|
|
$data = [ |
89
|
|
|
'status' => false, |
90
|
|
|
'message' => trans('admin.delete_failed'), |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return response()->json($data); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.