39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Fortify;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\Validation\Rule;
|
|
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
|
|
|
|
class UpdateUserProfileInformation implements UpdatesUserProfileInformation
|
|
{
|
|
/**
|
|
* Validate and update the given user's profile information.
|
|
*
|
|
* @param array<string, mixed> $input
|
|
*/
|
|
public function update(User $user, array $input): void
|
|
{
|
|
Validator::make($input, [
|
|
'display_name' => ['required', 'string', 'max:255'],
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'last_name' => ['max:255'],
|
|
'email' => ['email', 'max:255', Rule::unique('users')->ignore($user->id)],
|
|
'phone' => ['phone', 'max:20', Rule::unique('users')->ignore($user->id)],
|
|
'photo' => ['nullable', 'mimes:jpg,jpeg,png', 'max:1024'],
|
|
])->validateWithBag('updateProfileInformation');
|
|
|
|
if (isset($input['photo'])) {
|
|
$user->updateProfilePhoto($input['photo']);
|
|
}
|
|
|
|
$user->forceFill(
|
|
collect($input)
|
|
->only(['display_name', 'first_name', 'last_name', 'email', 'phone'])
|
|
->toArray()
|
|
)->save();
|
|
}
|
|
}
|