-
Notifications
You must be signed in to change notification settings - Fork 139
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 React starter kit #74
base: main
Are you sure you want to change the base?
Conversation
How did you manage to send multipart form data using the patch method? I had to change the form method const { data, setData, post, errors, processing, recentlySuccessful } = useForm<Required<ProfileForm>>({
name: auth.user.name,
email: auth.user.email,
avatar: null,
_method: 'patch',
});
const submit: FormEventHandler = (e) => {
e.preventDefault();
post(route('profile.update'), {
preserveScroll: true,
});
}; Finally, to prevent changing the user's avatar to public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
if ($request->avatar === null) {
$request->user()->avatar = $request->user()->getOriginal('avatar');
}
if ($request->hasFile('avatar')) {
if ($request->user()->avatar && Storage::exists($request->user()->avatar)) {
Storage::delete($request->user()->avatar);
}
$request->user()->avatar = $request->file('avatar')->store('avatars', 'public');
}
$request->user()->save();
return to_route('profile.edit');
} |
…le photo upload and deletion functionality
@haiffy420 |
@bennajah, looks very cool. I'll be testing this soon. Thanks! |
@tnylea |
Would be awesome to see this, I often need avatars in my projects. (and sometimes gravatar doesn't suffice!) |
@bennajah Really appreciate the contribution and thanks for adding a test to this as well 👏 Before we merge this in, can you resolve the conflict in the Also, I would like to eventually add the ability for users to crop their photos similar to this: image-crop.mp4But that can come later ;) Ok, if you can make those updates we can get this puppy in there. Thanks again! |
@tnylea The issue has been resolved! Additionally, I’ve implemented image cropping functionality using the react-image-crop library. It’s now fully integrated and working as expected. Let me know if you have any feedback or need further adjustments! Recording.2025-03-20.012223.mp4 |
Excellent! Thanks @bennajah. Can you remove the Great job 👏 |
Done |
Will the crop functionality work in the starter kit? |
Currently only in react starter kit |
feat: add profile avatar functionality to Laravel React starter kit
profile_photo_path
column to users migrationavatar
toUser
model for profile photo handlinggetAvatarAttribute()
accessor to fetch user's profile photo URL