first&last
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Profile;
|
||||
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Livewire\Attributes\Layout;
|
||||
use Livewire\Component;
|
||||
|
||||
#[Layout('layouts.app')]
|
||||
class ProfilePage extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
|
||||
public string $email = '';
|
||||
|
||||
public string $phone = '';
|
||||
|
||||
public string $password = '';
|
||||
|
||||
public string $password_confirmation = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$user = auth()->user();
|
||||
$this->name = $user->name;
|
||||
$this->email = $user->email;
|
||||
$this->phone = (string) $user->phone;
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$this->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'email', Rule::unique('users', 'email')->ignore(auth()->id())],
|
||||
'phone' => ['nullable', 'string', 'max:32'],
|
||||
'password' => ['nullable', 'string', 'same:password_confirmation', 'min:8'],
|
||||
]);
|
||||
|
||||
$user = auth()->user();
|
||||
$payload = [
|
||||
'name' => $this->name,
|
||||
'email' => $this->email,
|
||||
'phone' => $this->phone,
|
||||
];
|
||||
|
||||
if ($this->password !== '') {
|
||||
$payload['password'] = Hash::make($this->password);
|
||||
}
|
||||
|
||||
$user->update($payload);
|
||||
|
||||
session()->flash('success', 'Профиль обновлен.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.profile.profile-page')->title('Профиль');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user