-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add profile avatar functionality to Laravel Livewire starter kit #60
base: main
Are you sure you want to change the base?
Conversation
I think this should be done for vue and react too |
I have already do that |
* | ||
* @return string|null | ||
*/ | ||
public function getAvatarAttribute(): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bennajah don't you think it would be great if you extract the main logic in a trait? And, instead of using the logic in the livewire itself to move it in the trait?
/**
* Update the user's profile photo.
*/
public function updateProfilePhoto(UploadedFile $photo, string $storagePath = 'profile-photos'): void
{
tap($this->profile_photo_path, function ($previous) use ($photo, $storagePath) {
$this->forceFill([
'profile_photo_path' => $photo->storePublicly(
$storagePath, ['disk' => $this->profilePhotoDisk()]
),
])->save();
if ($previous) {
Storage::disk($this->profilePhotoDisk())->delete($previous);
}
});
}
/**
* Update the profile information for the currently authenticated user.
*/
public function updateProfileInformation(): void
{
$user = Auth::user();
$validated = $this->validate([
'profile_photo_path' => ['nullable', 'image', 'max:5048'],
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'lowercase',
'email',
'max:255',
Rule::unique(User::class)->ignore($user->id),
],
]);
$user->fill($validated);
if ($this->profile_photo_path) {
$user->updateProfilePhoto($validated['profile_photo_path']);
}
if ($user->isDirty('email')) {
$user->email_verified_at = null;
}
$user->save();
$this->dispatch('profile-updated', name: $user->name);
} |
@bennajah You're killing it 💪 Thanks for the Pull Requests. Yeah, in this one if you could also update the I also noticed that this one does not update the user menu avatar or remove the photo immediately without a page reload. The profile-photo-livewire.mp4Really appreciate it! |
feat: add profile avatar functionality to Laravel Livewire starter kit
profile_photo_path
column to users migrationavatar
toUser
model for profile photo handlinggetAvatarAttribute()
accessor to fetch user's profile photo URL