Skip to content

Commit

Permalink
allow ip address to be null, and attempt to autopopulate from request
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Dixon committed Jan 15, 2017
1 parent 77d4c94 commit 0603a89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## 0.0.5 - 2017-01-15
### Changed
- Allow ip address to be null in database
- Auto populate ip address from Request

## 0.0.4 - 2015-01-08
### Added
- Allow the user_id column to be null, so that artisan commands that use
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Once installed add the service provider and facade to your app config

'providers' => [
'...',
'Mintbridge\EloquentAuditing\AuditServiceProvider',
Mintbridge\EloquentAuditing\AuditServiceProvider::class,
];

'aliases' => [
...
'Auditor' => 'Mintbridge\EloquentAuditing\AuditorFacade',
'Auditor' => Mintbridge\EloquentAuditing\AuditorFacade::class,
];
```

Expand Down Expand Up @@ -73,4 +73,3 @@ Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

11 changes: 8 additions & 3 deletions src/Auditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
namespace Mintbridge\EloquentAuditing;

use Auth;
use Request;
use Mintbridge\EloquentAuditing\Activity;

class Auditor
{
public static function record($eventName, $model)
{
// save change data with event
$action = new Activity([
$activity = new Activity([
'event' => $eventName,
'data' => $model->getDirty()
]);

if ($ip = Request::ip()) {
$activity->ip_address = $ip;
}

// set the user
$action->user()->associate(Auth::user());
$activity->user()->associate(Auth::user());

$model->activities()->save($action);
$model->activities()->save($activity);
}
}
2 changes: 1 addition & 1 deletion src/migrations/create_activities_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class CreateActivitiesTable extends Migration
$table->integer('user_id')->nullable();
$table->string('event');
$table->text('data')->nullable();
$table->string('ip_address', 64);
$table->string('ip_address', 64)->nullable();
$table->timestamps();
});
}
Expand Down

0 comments on commit 0603a89

Please sign in to comment.