Skip to content

Commit

Permalink
Add fields for saving user's IP and current request route when logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
achillesp committed May 22, 2016
1 parent d4ebbfa commit 73daab3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
33 changes: 33 additions & 0 deletions database/migrations/2016_05_22_190217_add_fields_to_log_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddFieldsToLogTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('logs', function (Blueprint $table) {
$table->string('route')->after('type')->nullable();
$table->ipAddress('ip')->after('route')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('logs', function (Blueprint $table) {
$table->dropColumn('route');
$table->dropColumn('ip');
});
}
}
2 changes: 2 additions & 0 deletions src/AuditingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public function audit(array $log, $type)
'owner_id' => $this->getKey(),
'user_id' => $this->getUserId(),
'type' => $type,
'route' => \Request::route()->getName() ? \Request::route()->getName() : \Request::route()->getUri(),
'ip' => \Request::ip(),
'created_at' => new \DateTime(),
'updated_at' => new \DateTime(),
];
Expand Down

0 comments on commit 73daab3

Please sign in to comment.