43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Account;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class ProfileService
|
|
{
|
|
/**
|
|
* @param array<string, mixed> $validated
|
|
*/
|
|
public function update(array $validated, User $user): void
|
|
{
|
|
DB::transaction(function () use ($user, $validated): void {
|
|
$user->email = $validated['email'];
|
|
$user->username = $validated['username'];
|
|
$user->save();
|
|
|
|
$user->profile()->updateOrCreate(
|
|
['user_id' => $user->id],
|
|
[
|
|
'full_name' => $validated['full_name'],
|
|
'phone_number' => $validated['phone_number'] ?? null,
|
|
'gender' => $validated['gender'] ?? null,
|
|
'birth_date' => $validated['birth_date'] ?? null,
|
|
'address' => $validated['address'] ?? null,
|
|
],
|
|
);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Update user password.
|
|
*/
|
|
public function updatePassword(User $user, string $password): void
|
|
{
|
|
$user->password = Hash::make($password);
|
|
$user->save();
|
|
}
|
|
}
|