Skip to content

Commit

Permalink
package: add audit
Browse files Browse the repository at this point in the history
  • Loading branch information
arthaud-proust committed Oct 27, 2023
1 parent 6b9224c commit 4360bbb
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Models/PigeonMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;
use OwenIt\Auditing\Contracts\Auditable;

class PigeonMessage extends Pivot
class PigeonMessage extends Pivot implements Auditable
{
use HasFactory;
use \OwenIt\Auditing\Auditable;

protected $table = 'pigeon_messages';

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"owen-it/laravel-auditing": "^13.5",
"spatie/laravel-data": "^3.9",
"spatie/laravel-typescript-transformer": "^2.3",
"tightenco/ziggy": "^1.0"
Expand Down
90 changes: 89 additions & 1 deletion composer.lock

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

52 changes: 52 additions & 0 deletions database/migrations/2023_10_27_070151_create_audits_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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()
{
$connection = config('audit.drivers.database.connection', config('database.default'));
$table = config('audit.drivers.database.table', 'audits');

Schema::connection($connection)->create($table, function (Blueprint $table) {

$morphPrefix = config('audit.user.morph_prefix', 'user');

$table->bigIncrements('id');
$table->string($morphPrefix . '_type')->nullable();
$table->unsignedBigInteger($morphPrefix . '_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', 1023)->nullable();
$table->string('tags')->nullable();
$table->timestamps();

$table->index([$morphPrefix . '_id', $morphPrefix . '_type']);
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$connection = config('audit.drivers.database.connection', config('database.default'));
$table = config('audit.drivers.database.table', 'audits');

Schema::connection($connection)->drop($table);
}
}

0 comments on commit 4360bbb

Please sign in to comment.