/
UpdateProfileInformationForm.php
115 lines (94 loc) · 2.72 KB
/
UpdateProfileInformationForm.php
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
namespace Wallo\FilamentCompanies\Http\Livewire;
use App\Models\User;
use Filament\Notifications\Notification;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation;
use Livewire\Component;
use Livewire\Redirector;
use Livewire\WithFileUploads;
use Wallo\FilamentCompanies\Pages\User\Profile;
class UpdateProfileInformationForm extends Component
{
use WithFileUploads;
/**
* The component's state.
*/
public array $state = [];
/**
* The new avatar for the user.
*/
public $photo;
/**
* Determine if the verification email was sent.
*/
public bool $verificationLinkSent = false;
/**
* Prepare the component.
*/
public function mount(): void
{
$this->state = Auth::user()?->withoutRelations()->toArray();
}
/**
* Update the user's profile information.
*/
public function updateProfileInformation(UpdatesUserProfileInformation $updater): Redirector|RedirectResponse
{
$this->resetErrorBag();
$updater->update(
Auth::user(),
$this->photo
? array_merge($this->state, ['photo' => $this->photo])
: $this->state
);
if (isset($this->photo)) {
$this->profileInformationUpdated();
return redirect(Profile::getUrl());
}
$this->profileInformationUpdated();
$this->emit('refresh-navigation-menu');
return redirect()->back(303);
}
protected function profileInformationUpdated(): void
{
Notification::make()
->title(__('filament-companies::default.notifications.profile_information_updated.title'))
->success()
->body(__('filament-companies::default.notifications.profile_information_updated.body'))
->send();
}
/**
* Delete user's profile photo.
*/
public function deleteProfilePhoto(): void
{
Auth::user()?->deleteProfilePhoto();
$this->emit('refresh-navigation-menu');
}
/**
* Sent the email verification.
*/
public function sendEmailVerification(): void
{
Auth::user()?->sendEmailVerificationNotification();
$this->verificationLinkSent = true;
}
/**
* Get the current user of the application.
*/
public function getUserProperty(): User|Authenticatable|null
{
return Auth::user();
}
/**
* Render the component.
*/
public function render(): View
{
return view('filament-companies::profile.update-profile-information-form');
}
}