36 lines
845 B
PHP
36 lines
845 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Support\Facades\Hash;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Service to handle User Profile updates.
|
||
|
|
*/
|
||
|
|
class ProfileService
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Update the user profile information.
|
||
|
|
*
|
||
|
|
* @param User $user The user model to update.
|
||
|
|
* @param array $data Data containing name, email, and optionally a new password.
|
||
|
|
* @return bool True if the update was successful.
|
||
|
|
* @throws Exception If there's an issue during the update process.
|
||
|
|
*/
|
||
|
|
public function update(User $user, array $data): bool
|
||
|
|
{
|
||
|
|
$user->fill([
|
||
|
|
'name' => $data['name'],
|
||
|
|
'email' => $data['email'],
|
||
|
|
]);
|
||
|
|
|
||
|
|
if (!empty($data['new_password'])) {
|
||
|
|
$user->password = Hash::make($data['new_password']);
|
||
|
|
}
|
||
|
|
|
||
|
|
return $user->save();
|
||
|
|
}
|
||
|
|
}
|