diff --git a/composer.json b/composer.json index 1319d2e..1d7c9db 100644 --- a/composer.json +++ b/composer.json @@ -43,6 +43,9 @@ "dev-master": "1.0-dev" } }, + "suggest": { + "jenssegers/agent": "Required to use logging client info (~2.5)." + }, "config": { "sort-packages": true } diff --git a/database/migrations/2017_04_26_140701_create_action_log_table.php b/database/migrations/2017_04_26_140701_create_action_log_table.php index 3d71337..8c64498 100644 --- a/database/migrations/2017_04_26_140701_create_action_log_table.php +++ b/database/migrations/2017_04_26_140701_create_action_log_table.php @@ -34,6 +34,9 @@ public function up() $table->string('client_ip', 20) ->comment('操作者IP'); + $table->string('client') + ->comment('客户端信息'); + $table->timestamps(); $table->index('user_id'); diff --git a/src/Events/AbstractEvent.php b/src/Events/AbstractEvent.php index 2e4e529..34fc39e 100644 --- a/src/Events/AbstractEvent.php +++ b/src/Events/AbstractEvent.php @@ -23,6 +23,21 @@ public function __construct(Model $model) 'client_ip' => request()->getClientIp(), 'type' => $this->type, ]); + + if (class_exists('\Jenssegers\Agent\Agent')) { + $agent = new \Jenssegers\Agent\Agent(); + + $device = $agent->device(); + $platform = $agent->platform(); + $browser = $agent->browser(); + + $this->setAttribute('client', [ + 'device' => $device . ' ' . $agent->version($device), + 'platform' => $platform . ' ' . $agent->version($platform), + '$browser' => $browser . ' ' . $agent->version($browser), + ]); + } + } public function getContent() diff --git a/src/Factory.php b/src/Factory.php index 7439be5..6281994 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -29,6 +29,7 @@ public function event(AbstractEvent $event) $log->table_name = $event->getAttribute('model.table', ''); $log->content = json_encode($event->getContent()); $log->client_ip = $event->getAttribute('client_ip', ''); + $log->client = json_encode($event->getAttribute('client', [])); $log->save(); diff --git a/src/Models/ActionLogModel.php b/src/Models/ActionLogModel.php index 6f1b9ef..12790cb 100644 --- a/src/Models/ActionLogModel.php +++ b/src/Models/ActionLogModel.php @@ -13,6 +13,7 @@ * @property string $type 操作类型 * @property string $table_name 相关的数据表 * @property string $content 操作描述 + * @property string $client 客户端信息 * @property string $client_ip 操作者IP * @property \Carbon\Carbon $created_at * @property \Carbon\Carbon $updated_at