misc_pterodactyl-panel/app/Services/Users/UserUpdateService.php

38 lines
797 B
PHP
Raw Permalink Normal View History

<?php
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Traits\Services\HasUserLevels;
class UserUpdateService
{
use HasUserLevels;
/**
* UserUpdateService constructor.
*/
public function __construct(private Hasher $hasher)
{
}
/**
* Update the user model instance and return the updated model.
*
* @throws \Throwable
*/
public function handle(User $user, array $data): User
{
2021-01-23 20:33:34 +00:00
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
2018-02-08 03:13:40 +00:00
} else {
unset($data['password']);
}
$user->forceFill($data)->saveOrFail();
return $user->refresh();
}
}