Files
panel-pelican-dev/app/Services/Users/UserUpdateService.php

35 lines
772 B
PHP
Raw Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Services\Users;
2024-03-12 22:39:16 -04:00
use App\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
2024-03-12 22:39:16 -04:00
use App\Traits\Services\HasUserLevels;
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
{
2021-01-23 12:33:34 -08:00
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
2018-02-07 21:13:40 -06:00
} else {
unset($data['password']);
}
$user->forceFill($data)->saveOrFail();
return $user->refresh();
}
}