|
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\Facades\Admin; |
|
8
|
|
|
use Encore\Admin\Grid; |
|
9
|
|
|
use Encore\Admin\Layout\Content; |
|
10
|
|
|
use Illuminate\Routing\Controller; |
|
11
|
|
|
|
|
12
|
|
|
class LogController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Index interface. |
|
16
|
|
|
* |
|
17
|
|
|
* @return Content |
|
18
|
|
|
*/ |
|
19
|
|
|
public function index() |
|
20
|
|
|
{ |
|
21
|
|
|
return Admin::content(function (Content $content) { |
|
22
|
|
|
$content->header(trans('admin::lang.operation_log')); |
|
|
|
|
|
|
23
|
|
|
$content->description(trans('admin::lang.list')); |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
$grid = Admin::grid(OperationLog::class, function (Grid $grid) { |
|
26
|
|
|
$grid->model()->orderBy('id', 'DESC'); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$grid->id('ID')->sortable(); |
|
|
|
|
|
|
29
|
|
|
$grid->user()->name(); |
|
|
|
|
|
|
30
|
|
|
$grid->method()->value(function ($method) { |
|
|
|
|
|
|
31
|
|
|
$color = array_get(OperationLog::$methodColors, $method, 'grey'); |
|
32
|
|
|
|
|
33
|
|
|
return "<span class=\"badge bg-$color\">$method</span>"; |
|
34
|
|
|
}); |
|
35
|
|
|
$grid->path()->label('info'); |
|
|
|
|
|
|
36
|
|
|
$grid->ip()->label('primary'); |
|
|
|
|
|
|
37
|
|
|
$grid->input()->value(function ($input) { |
|
|
|
|
|
|
38
|
|
|
$input = json_decode($input, true); |
|
39
|
|
|
$input = array_except($input, '_pjax'); |
|
40
|
|
|
|
|
41
|
|
|
return '<code>'.json_encode($input, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).'</code>'; |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
$grid->created_at(trans('admin::lang.created_at')); |
|
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
$grid->rows(function ($row) { |
|
47
|
|
|
$row->actions('delete'); |
|
48
|
|
|
}); |
|
49
|
|
|
|
|
50
|
|
|
$grid->filter(function ($filter) { |
|
51
|
|
|
$filter->is('user_id', 'User')->select(Administrator::all()->pluck('name', 'id')); |
|
52
|
|
|
$filter->is('method')->select(array_combine(OperationLog::$methods, OperationLog::$methods)); |
|
53
|
|
|
$filter->like('path'); |
|
54
|
|
|
$filter->is('ip'); |
|
55
|
|
|
}); |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
$content->body($grid); |
|
59
|
|
|
}); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function destroy($id) |
|
63
|
|
|
{ |
|
64
|
|
|
$ids = explode(',', $id); |
|
65
|
|
|
|
|
66
|
|
|
OperationLog::destroy(array_filter($ids)); |
|
67
|
|
|
|
|
68
|
|
|
return response()->json(['msg' => 'delete success!']); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.