Path: blob/1.0-develop/app/Services/Users/UserUpdateService.php
14043 views
<?php12namespace Pterodactyl\Services\Users;34use Pterodactyl\Models\User;5use Illuminate\Contracts\Hashing\Hasher;6use Pterodactyl\Events\User\PasswordChanged;7use Pterodactyl\Traits\Services\HasUserLevels;89class UserUpdateService10{11use HasUserLevels;1213/**14* UserUpdateService constructor.15*/16public function __construct(private Hasher $hasher)17{18}1920/**21* Update the user model instance and return the updated model.22*23* @throws \Throwable24*/25public function handle(User $user, array $data): User26{27if (!empty(array_get($data, 'password'))) {28$data['password'] = $this->hasher->make($data['password']);29} else {30unset($data['password']);31}3233$user->forceFill($data)->saveOrFail();3435if (isset($data['password'])) {36PasswordChanged::dispatch($user);37}3839return $user->refresh();40}41}424344