Implement superadmin audit log for mutations
This commit is contained in:
42
database/factories/SuperAdminActionLogFactory.php
Normal file
42
database/factories/SuperAdminActionLogFactory.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SuperAdminActionLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SuperAdminActionLog>
|
||||
*/
|
||||
class SuperAdminActionLogFactory extends Factory
|
||||
{
|
||||
protected $model = SuperAdminActionLog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'actor_id' => User::factory(),
|
||||
'action' => $this->faker->randomElement([
|
||||
'tenant.updated',
|
||||
'photo.approved',
|
||||
'user.created',
|
||||
]),
|
||||
'subject_type' => User::class,
|
||||
'subject_id' => User::factory(),
|
||||
'source' => $this->faker->randomElement([
|
||||
'App\\Filament\\Resources\\TenantResource',
|
||||
'App\\Filament\\Clusters\\DailyOps\\Resources\\Photos\\PhotoResource',
|
||||
]),
|
||||
'metadata' => [
|
||||
'fields' => ['status', 'moderated_at'],
|
||||
],
|
||||
'occurred_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('super_admin_action_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('actor_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('action', 120);
|
||||
$table->nullableMorphs('subject');
|
||||
$table->string('source', 200)->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamp('occurred_at')->useCurrent();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['action', 'occurred_at']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('super_admin_action_logs');
|
||||
}
|
||||
};
|
||||
19
database/seeders/SuperAdminActionLogSeeder.php
Normal file
19
database/seeders/SuperAdminActionLogSeeder.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\SuperAdminActionLog;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SuperAdminActionLogSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
SuperAdminActionLog::factory()
|
||||
->count(10)
|
||||
->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user