coolify/app/Livewire/Profile/Index.php

40 lines
839 B
PHP
Raw Normal View History

2023-05-22 22:30:33 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Profile;
2023-05-22 22:30:33 +02:00
2023-12-08 09:15:32 +01:00
use Livewire\Attributes\Validate;
2023-05-22 22:30:33 +02:00
use Livewire\Component;
2024-01-07 16:23:41 +01:00
class Index extends Component
2023-05-22 22:30:33 +02:00
{
public int $userId;
public string $email;
2023-12-08 09:15:32 +01:00
#[Validate('required')]
public string $name;
2023-05-22 22:30:33 +02:00
public function mount()
{
$this->userId = auth()->user()->id;
$this->name = auth()->user()->name;
$this->email = auth()->user()->email;
}
public function submit()
{
try {
$this->validate();
2023-12-08 09:15:32 +01:00
auth()->user()->update([
2023-05-22 22:30:33 +02:00
'name' => $this->name,
]);
2023-12-08 09:15:32 +01:00
$this->dispatch('success', 'Profile updated successfully.');
2023-06-09 15:55:21 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-22 22:30:33 +02:00
}
}
2024-01-07 16:23:41 +01:00
public function render()
{
return view('livewire.profile.index');
}
2023-05-22 22:30:33 +02:00
}