Files
panel-pelican-dev/app/Services/Users/UserUpdateService.php
Boy132 1817383bf5 Add changes from upstream (#2293)
Co-authored-by: DaneEveritt <dane@daneeveritt.com>
Co-authored-by: danny6167 <danielb@purpleflaghosting.com>
Co-authored-by: MrSoulPenguin <28676680+MrSoulPenguin@users.noreply.github.com>
2026-04-20 17:25:54 +02:00

41 lines
920 B
PHP

<?php
namespace App\Services\Users;
use App\Events\User\PasswordChanged;
use App\Models\User;
use App\Traits\Services\HasUserLevels;
use Illuminate\Contracts\Hashing\Hasher;
use Throwable;
class UserUpdateService
{
use HasUserLevels;
public function __construct(private readonly Hasher $hasher) {}
/**
* Update the user model instance and return the updated model.
*
* @param array<array-key, mixed> $data
*
* @throws Throwable
*/
public function handle(User $user, array $data): User
{
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
} else {
unset($data['password']);
}
$user->forceFill($data)->saveOrFail();
if (isset($data['password'])) {
PasswordChanged::dispatch($user);
}
return $user->refresh();
}
}