pelican-panel-mirror/app/Services/Users/UserUpdateService.php
Boy132 d555c42644
Update all dependencies (#712)
* update composer.lock

* run pint

* fix phpstan

* update migrations (sqlite `dropForeign`)

* fix migrations

* Reset these back for now

* Alphabetize the rules

* run `php artisan filament:upgrade`

---------

Co-authored-by: Lance Pioch <git@lance.sh>
2024-11-22 09:27:57 +01:00

36 lines
764 B
PHP

<?php
namespace App\Services\Users;
use App\Models\User;
use Illuminate\Contracts\Hashing\Hasher;
use App\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
{
if (!empty(array_get($data, 'password'))) {
$data['password'] = $this->hasher->make($data['password']);
} else {
unset($data['password']);
}
$user->forceFill($data)->saveOrFail();
return $user->refresh();
}
}