feat: log section
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Persistent audit log of authentication events (OTP sends, OTP checks,
|
||||
* password logins, registrations). otp_tokens rows are deleted as soon as
|
||||
* they are consumed, so they cannot be used to count SMS usage or logins —
|
||||
* this table keeps one immutable row per event for the admin analytics.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('auth_logs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->string('mobile')->nullable();
|
||||
$table->string('email')->nullable();
|
||||
// See App\Models\AuthLog::EVENTS
|
||||
$table->string('event');
|
||||
$table->string('package_name')->nullable();
|
||||
// PackageName::SOURCES code the request came from (store/web/…)
|
||||
$table->unsignedTinyInteger('source')->nullable();
|
||||
$table->boolean('success')->default(true);
|
||||
// True when the event actually triggered an outgoing SMS (billable)
|
||||
$table->boolean('sms_sent')->default(false);
|
||||
$table->string('ip', 45)->nullable();
|
||||
$table->string('user_agent')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['event', 'created_at']);
|
||||
$table->index('mobile');
|
||||
$table->index('created_at');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('auth_logs');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user