forked from eatvio/eatvio-infra
68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Profile;
|
|
|
|
use App\Livewire\Forms\ProfileEditDetailzForm;
|
|
use App\Models\User;
|
|
use App\Models\UserDetailz;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Support\Facades\Validator;
|
|
use Illuminate\View\View;
|
|
use Livewire\Component;
|
|
|
|
class EditDetailzForm extends Component
|
|
{
|
|
public User $user;
|
|
|
|
public UserDetailz $detailz;
|
|
|
|
public string $currentPassword;
|
|
|
|
public string $newPassword = '';
|
|
|
|
public string $newPasswordConfirm = '';
|
|
|
|
public array $validatedData = [];
|
|
|
|
public ProfileEditDetailzForm $detailzForm;
|
|
|
|
public function mount(User $user): void
|
|
{
|
|
$this->detailz = $user->detailz;
|
|
$this->detailzForm->setDetailz($user->detailz);
|
|
}
|
|
|
|
public function updatePassword(): void
|
|
{
|
|
$validatedData = Validator::make(
|
|
['currentPassword' => $this->currentPassword, 'newPassword' => $this->newPassword, 'newPasswordConfirm' => $this->newPasswordConfirm],
|
|
['currentPassword' => 'required|string|min:6', 'newPassword' => 'required|string|min:6', 'newPasswordConfirm' => 'required|string|min:6'],
|
|
['required' => 'The :attribute field is required']
|
|
)->after(function ($validator) {
|
|
if (! isset($this->currentPassword) || ! Hash::check($this->currentPassword, $this->user->password)) {
|
|
$validator->errors()->add('currentPassword', __('The provided password does not match your current password.'));
|
|
}
|
|
if ($this->newPassword !== $this->newPasswordConfirm) {
|
|
$validator->errors()->add('newPasswordConfirm', __('The password and confirm password fields do not match.'));
|
|
}
|
|
})->validate();
|
|
/* dd($validatedData); */
|
|
$this->user->forceFill([
|
|
'password' => Hash::make($validatedData['newPassword']),
|
|
])->save();
|
|
$this->validatedData = $validatedData;
|
|
$this->reset(['currentPassword', 'newPassword', 'newPasswordConfirm']);
|
|
/* dd($this->currentPassword, $this->newPassword, $this->newPasswordConfirm, $validatedData); */
|
|
}
|
|
|
|
public function refineDetailz(): void
|
|
{
|
|
$this->detailzForm->update();
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.profile.edit-detailz-form');
|
|
}
|
|
}
|