Files
laraundfelix/app/Domain/Catalog/IdentityProfile.php
T
LarsandCursor 5e763d15ec
Deploy Test / test (push) Successful in 17s
Deploy Test / deploy (push) Successful in 25s
Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-16 08:24:23 +01:00

40 lines
1.1 KiB
PHP

<?php
namespace App\Domain\Catalog;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
class IdentityProfile
{
/**
* @param array<string, mixed> $fields
*/
public function fill(Model $subject, array $fields, ?User $actor = null): void
{
foreach ($fields as $field => $value) {
$next = is_string($value) ? trim($value) : $value;
$next = $next === '' ? null : $next;
$before = $subject->getAttribute($field);
$before = $before === '' ? null : $before;
if ($before === $next) {
continue;
}
$subject->setAttribute($field, $next);
IdentityChange::query()->create([
'subject_type' => $subject->getMorphClass(),
'subject_id' => $subject->getKey(),
'field' => $field,
'before' => $before,
'after' => $next,
'actor_id' => $actor?->id,
'occurred_at' => now(),
]);
}
$subject->save();
}
}