forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserUpdateService.php
More file actions
43 lines (35 loc) · 905 Bytes
/
UserUpdateService.php
File metadata and controls
43 lines (35 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Pterodactyl\Services\Users;
use Pterodactyl\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
use Pterodactyl\Traits\Services\HasUserLevels;
class UserUpdateService
{
use HasUserLevels;
/**
* @var \Illuminate\Contracts\Hashing\Hasher
*/
private $hasher;
/**
* UpdateService constructor.
*/
public function __construct(Hasher $hasher)
{
$this->hasher = $hasher;
}
/**
* Update the user model instance and return the updated model.
*
* @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();
return $user->refresh();
}
}