2023-05-22 20:30:33 +00:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 18:06:32 +00:00
|
|
|
namespace App\Livewire\Profile;
|
2023-05-22 20:30:33 +00:00
|
|
|
|
2023-12-08 08:15:32 +00:00
|
|
|
use Livewire\Attributes\Validate;
|
2023-05-22 20:30:33 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Form extends Component
|
|
|
|
{
|
|
|
|
public int $userId;
|
|
|
|
public string $email;
|
|
|
|
|
2023-12-08 08:15:32 +00:00
|
|
|
#[Validate('required')]
|
|
|
|
public string $name;
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-22 20:30:33 +00:00
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->userId = auth()->user()->id;
|
|
|
|
$this->name = auth()->user()->name;
|
|
|
|
$this->email = auth()->user()->email;
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-22 20:30:33 +00:00
|
|
|
public function submit()
|
|
|
|
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->validate();
|
2023-12-08 08:15:32 +00:00
|
|
|
auth()->user()->update([
|
2023-05-22 20:30:33 +00:00
|
|
|
'name' => $this->name,
|
|
|
|
]);
|
2023-12-08 08:15:32 +00:00
|
|
|
|
|
|
|
$this->dispatch('success', 'Profile updated successfully.');
|
2023-06-09 13:55:21 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-15 13:34:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-22 20:30:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|