feat: add ActivityLog model and migration with record() helper
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user