68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Fortify;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
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, string> $input
|
|
*/
|
|
public function update(User $user, array $input): void
|
|
{
|
|
Validator::make($input, [
|
|
'first_name' => ['required', 'string', 'max:255'],
|
|
'last_name' => ['required', 'string', 'max:255'],
|
|
'judging_preference' => ['required', 'string', 'max:255'],
|
|
'cell_phone' => ['required', 'string', 'max:255'],
|
|
|
|
'email' => [
|
|
'required',
|
|
'string',
|
|
'email',
|
|
'max:255',
|
|
Rule::unique('users')->ignore($user->id),
|
|
],
|
|
])->validate();
|
|
|
|
if ($input['email'] !== $user->email &&
|
|
$user instanceof MustVerifyEmail) {
|
|
$this->updateVerifiedUser($user, $input);
|
|
} else {
|
|
$user->forceFill([
|
|
'first_name' => $input['first_name'],
|
|
'last_name' => $input['last_name'],
|
|
'judging_preference' => $input['judging_preference'],
|
|
'cell_phone' => $input['cell_phone'],
|
|
'email' => $input['email'],
|
|
])->save();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Update the given verified user's profile information.
|
|
*
|
|
* @param array<string, string> $input
|
|
*/
|
|
protected function updateVerifiedUser(User $user, array $input): void
|
|
{
|
|
$user->forceFill([
|
|
'first_name' => $input['first_name'],
|
|
'last_name' => $input['last_name'],
|
|
'judging_preference' => $input['judging_preference'],
|
|
'cell_phone' => $input['cell_phone'],
|
|
'email' => $input['email'],
|
|
'email_verified_at' => null,
|
|
])->save();
|
|
|
|
$user->sendEmailVerificationNotification();
|
|
}
|
|
}
|