Files
WebAPP/app/Models/ActivityLog.php
Rhino 2e24a40d68 Stand: SMTP-Test, Admin-Mail-Tab, Notifiable-Fix, Lazy-Quill
- Fix: Notifiable-Trait zum User-Model hinzugefuegt (behebt notify()-500er)
- Installer: SMTP-Verbindungstest mit EsmtpTransport + Ueberspringen-Link
- Admin: Neuer E-Mail-Tab mit SMTP-Konfiguration + Verbindungstest
- Admin: Lazy Quill-Initialisierung (nur sichtbare Locale wird geladen)
- Uebersetzungen: 17 neue Mail-Keys in allen 6 Sprachen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 07:30:37 +01:00

70 lines
1.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ActivityLog extends Model
{
public $timestamps = false;
protected $fillable = [
'user_id',
'action',
'model_type',
'model_id',
'description',
'properties',
'created_at',
];
protected function casts(): array
{
return [
'properties' => 'array',
'created_at' => 'datetime',
];
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class)->withTrashed();
}
public static function log(
string $action,
string $description,
?string $modelType = null,
?int $modelId = null,
?array $properties = null,
): self {
$log = new static();
$log->user_id = auth()->id();
$log->action = $action;
$log->model_type = $modelType;
$log->model_id = $modelId;
$log->description = $description;
$log->properties = $properties;
$log->ip_address = request()->ip();
$log->created_at = now();
$log->save();
return $log;
}
public static function logWithChanges(
string $action,
string $description,
?string $modelType = null,
?int $modelId = null,
?array $old = null,
?array $new = null,
): self {
$properties = null;
if ($old !== null || $new !== null) {
$properties = array_filter(['old' => $old, 'new' => $new], fn ($v) => $v !== null);
}
return static::log($action, $description, $modelType, $modelId, $properties ?: null);
}
}