Skip to content

Commit 73daab3

Browse files
committed
Add fields for saving user's IP and current request route when logging.
1 parent d4ebbfa commit 73daab3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddFieldsToLogTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('logs', function (Blueprint $table) {
16+
$table->string('route')->after('type')->nullable();
17+
$table->ipAddress('ip')->after('route')->nullable();
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('logs', function (Blueprint $table) {
29+
$table->dropColumn('route');
30+
$table->dropColumn('ip');
31+
});
32+
}
33+
}

src/AuditingTrait.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ public function audit(array $log, $type)
244244
'owner_id' => $this->getKey(),
245245
'user_id' => $this->getUserId(),
246246
'type' => $type,
247+
'route' => \Request::route()->getName() ? \Request::route()->getName() : \Request::route()->getUri(),
248+
'ip' => \Request::ip(),
247249
'created_at' => new \DateTime(),
248250
'updated_at' => new \DateTime(),
249251
];

0 commit comments

Comments
 (0)