Files

38 lines
797 B
PHP
Raw Permalink Normal View History

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