Ergaenze Stammdaten, Suche, Dimensionen, Abdeckung und Ausgabenachweis
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
7b54c38623
commit
5e763d15ec
23 files changed
+661
-5
No files matched your search
@@ -0,0 +1,39 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user