feat: add ActivityLog model and migration with record() helper

This commit is contained in:
GuavaPopper
2026-06-03 20:55:30 +07:00
parent 1fcad7d9b2
commit 7fb649f690
2 changed files with 58 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ActivityLog extends Model
{
protected $fillable = [
'user_id', 'user_name', 'action', 'description',
'subject_type', 'subject_id', 'ip_address',
];
public static function record(string $action, string $description, ?string $subjectType = null, $subjectId = null): void
{
static::create([
'user_id' => auth()->id(),
'user_name' => auth()->user()?->name,
'action' => $action,
'description' => $description,
'subject_type' => $subjectType,
'subject_id' => $subjectId !== null ? (string) $subjectId : null,
'ip_address' => request()->ip(),
]);
}
public function user()
{
return $this->belongsTo(User::class);
}
}