Skip to content

Commit

Permalink
Start recording changes to storage box model
Browse files Browse the repository at this point in the history
This will give us a history of previous owners of a storage box, which we can later build a UI for admins to see on site
  • Loading branch information
rjackson committed Apr 6, 2024
1 parent b3ea441 commit 8849126
Show file tree
Hide file tree
Showing 6 changed files with 271 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Entities/StorageBox.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace BB\Entities;

use Illuminate\Database\Eloquent\Model;
use OwenIt\Auditing\Contracts\Auditable;

/**
* Class StorageBox
Expand All @@ -9,8 +10,9 @@
* @property integer $user_id
* @package BB\Entities
*/
class StorageBox extends Model
class StorageBox extends Model implements Auditable
{
use \OwenIt\Auditing\Auditable;

/**
* The database table used by the model.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"michelf/php-markdown": "~1.4",
"nesbot/carbon": "~1.19",
"nuovo/spreadsheet-reader": "~0.5",
"owen-it/laravel-auditing": "^8.0",
"php-http/curl-client": "^2.3",
"php-http/message": "^1.16",
"php-http/message-factory": "^1.1",
Expand Down
89 changes: 88 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
NotificationChannels\Telegram\TelegramServiceProvider::class,
Sentry\Laravel\ServiceProvider::class,
Laravel\Tinker\TinkerServiceProvider::class,
OwenIt\Auditing\AuditingServiceProvider::class,

// Queueing emails with sync queue doesn't work on 5.3+ without Bus?
AltThree\Bus\BusServiceProvider::class,
Expand Down
135 changes: 135 additions & 0 deletions config/audit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Audit Implementation
|--------------------------------------------------------------------------
|
| Define which Audit model implementation should be used.
|
*/

'implementation' => OwenIt\Auditing\Models\Audit::class,

/*
|--------------------------------------------------------------------------
| User Morph prefix & Guards
|--------------------------------------------------------------------------
|
| Define the morph prefix and authentication guards for the User resolver.
|
*/

'user' => [
'morph_prefix' => 'user',
'guards' => [
'web',
'api',
],
],

/*
|--------------------------------------------------------------------------
| Audit Resolvers
|--------------------------------------------------------------------------
|
| Define the User, IP Address, User Agent and URL resolver implementations.
|
*/
'resolver' => [
'user' => OwenIt\Auditing\Resolvers\UserResolver::class,
'ip_address' => OwenIt\Auditing\Resolvers\IpAddressResolver::class,
'user_agent' => OwenIt\Auditing\Resolvers\UserAgentResolver::class,
'url' => OwenIt\Auditing\Resolvers\UrlResolver::class,
],

/*
|--------------------------------------------------------------------------
| Audit Events
|--------------------------------------------------------------------------
|
| The Eloquent events that trigger an Audit.
|
*/

'events' => [
'created',
'updated',
'deleted',
'restored',
],

/*
|--------------------------------------------------------------------------
| Strict Mode
|--------------------------------------------------------------------------
|
| Enable the strict mode when auditing?
|
*/

'strict' => false,

/*
|--------------------------------------------------------------------------
| Audit Timestamps
|--------------------------------------------------------------------------
|
| Should the created_at, updated_at and deleted_at timestamps be audited?
|
*/

'timestamps' => false,

/*
|--------------------------------------------------------------------------
| Audit Threshold
|--------------------------------------------------------------------------
|
| Specify a threshold for the amount of Audit records a model can have.
| Zero means no limit.
|
*/

'threshold' => 0,

/*
|--------------------------------------------------------------------------
| Audit Driver
|--------------------------------------------------------------------------
|
| The default audit driver used to keep track of changes.
|
*/

'driver' => 'database',

/*
|--------------------------------------------------------------------------
| Audit Driver Configurations
|--------------------------------------------------------------------------
|
| Available audit drivers and respective configurations.
|
*/

'drivers' => [
'database' => [
'table' => 'audits',
'connection' => null,
],
],

/*
|--------------------------------------------------------------------------
| Audit Console
|--------------------------------------------------------------------------
|
| Whether console events should be audited (eg. php artisan db:seed).
|
*/

'console' => false,
];
43 changes: 43 additions & 0 deletions database/migrations/2024_04_06_144921_create_audits_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

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

class CreateAuditsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('audits', function (Blueprint $table) {
$table->increments('id');
$table->string('user_type')->nullable();
$table->unsignedBigInteger('user_id')->nullable();
$table->string('event');
$table->morphs('auditable');
$table->text('old_values')->nullable();
$table->text('new_values')->nullable();
$table->text('url')->nullable();
$table->ipAddress('ip_address')->nullable();
$table->string('user_agent')->nullable();
$table->string('tags')->nullable();
$table->timestamps();

$table->index(['user_id', 'user_type']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('audits');
}
}

0 comments on commit 8849126

Please sign in to comment.