forked from tallstackui/starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProfile.php
More file actions
63 lines (49 loc) · 1.28 KB
/
Profile.php
File metadata and controls
63 lines (49 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Livewire\User;
use App\Livewire\Traits\Alert;
use App\Models\User;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
use Livewire\Component;
class Profile extends Component
{
use Alert;
public User $user;
public ?string $password = null;
public ?string $password_confirmation = null;
public function mount(): void
{
$this->user = Auth::user();
}
public function rules(): array
{
return [
'user.name' => [
'required',
'string',
'max:255'
],
'password' => [
'nullable',
'string',
'confirmed',
Rules\Password::defaults()
]
];
}
public function render(): View
{
return view('livewire.user.profile');
}
public function save(): void
{
$this->validate();
$this->user->password = when($this->password !== null, Hash::make($this->password), $this->user->password);
$this->user->update();
$this->dispatch('updated', name: $this->user->name);
$this->resetExcept('user');
$this->success();
}
}