This implementation adds comprehensive user profile management functionality to the Laravel social network application using Livewire components.
- Users can view their own profile at
/my-profile - Users can view other users' profiles at
/users/{userId}/profile - Profile displays:
- Profile photo
- Name and email
- Bio
- Location, website, gender, and birth date (if available)
- Friend/follower statistics
- Users can edit their profile at
/my-profile/edit - Editable fields:
- Name (required)
- Email (required, must be valid email)
- Bio (optional, max 1000 characters)
- Location (optional)
- Website (optional, must be valid URL)
- Gender (optional: male, female, other, prefer not to say)
- Birth date (optional, must be in the past)
- Profile photo (optional, image only, max 2MB)
- Upload new profile photo
- Delete existing profile photo
- Preview profile photo before saving
- Automatic photo validation (image type, max size 2MB)
-
Existing Migration:
2026_02_15_210000_add_bio_to_users_table.php- Adds
biocolumn touserstable (already exists) - Bio is stored in the users table, not the profiles table
- Adds
-
Models Updated:
User.php: Addedbioto fillable array, addedprofile()relationshipProfile.php: No changes needed (bio not stored here)
-
ShowProfile (
app/Http/Livewire/ShowProfile.php)- Displays user profile information
- Automatically creates profile if it doesn't exist
- Shows "Edit Profile" button for own profile
-
EditProfile (
app/Http/Livewire/EditProfile.php)- Handles profile editing with validation
- Supports profile photo upload and deletion
- Real-time validation with error messages
- Redirects to profile view after successful save
-
Livewire Views:
resources/views/livewire/show-profile.blade.php: Profile displayresources/views/livewire/edit-profile.blade.php: Profile editing form
-
Wrapper Views:
resources/views/user-profile/show.blade.php: Profile page wrapperresources/views/profile/edit.blade.php: Edit page wrapper
Added to routes/web.php (protected by auth middleware):
Route::get('/my-profile', ...)->name('user-profile.show');
Route::get('/my-profile/edit', ...)->name('user-profile.edit');
Route::get('/users/{userId}/profile', ...)->name('user-profile.view');Created comprehensive test suite in tests/Feature/ProfileTest.php with 25 test cases covering:
- Profile viewing functionality
- Profile editing functionality
- Validation rules
- Photo upload and deletion
- Access control
- Data persistence
- Install dependencies:
composer install - Set up database:
php artisan migrate:fresh --seed
- Generate application key:
php artisan key:generate - Link storage:
php artisan storage:link - Start the development server:
php artisan serve
- Log in to the application
- Navigate to
/my-profile - Verify you see:
- Your profile photo
- Your name and email
- Edit Profile button
- Bio (if set)
- Profile details (location, website, etc.)
- Friend/follower statistics
- From your profile, click "Edit Profile"
- Update the following fields:
- Name: "Updated Name"
- Bio: "This is my new bio"
- Location: "San Francisco, CA"
- Website: "https://example.com"
- Gender: Select an option
- Birth date: Select a past date
- Click "Save Changes"
- Verify you're redirected to your profile
- Verify all changes are displayed correctly
- Go to profile edit page
- Click "Select New Photo"
- Choose an image file (JPG/PNG, under 2MB)
- Verify preview shows the new photo
- Click "Save Changes"
- Verify the new photo appears on your profile
- Go to profile edit page (with a photo uploaded)
- Click "Remove Photo" button
- Verify the photo reverts to default avatar
- Verify the change is saved
Test each validation rule:
- Try to save with empty name (should show error)
- Try to save with invalid email (should show error)
- Try to save bio with >1000 characters (should show error)
- Try to upload non-image file as profile photo (should show error)
- Try to upload very large image >2MB (should show error)
- Try to set future birth date (should show error)
- Get another user's ID from the database
- Navigate to
/users/{userId}/profile - Verify you see their profile information
- Verify you do NOT see the "Edit Profile" button
- Log out of the application
- Try to access
/my-profile(should redirect to login) - Try to access
/my-profile/edit(should redirect to login)
Run the test suite:
php artisan test --filter=ProfileTestThis will execute 25 test cases covering all functionality.
✅ Users can view their profile information
- Implemented in ShowProfile component
- Route:
/my-profile
✅ Users can edit their name, email, bio, and other details
- Implemented in EditProfile component
- Route:
/my-profile/edit - All fields editable with proper validation
✅ Users can upload and change their profile picture
- Photo upload functionality in EditProfile
- Photo deletion functionality included
- Validation for image type and size
✅ Profile changes are reflected immediately across the platform
- Livewire provides real-time updates
- Changes persist to database
- Profile relationship ensures data consistency
Beyond the requirements, this implementation includes:
- Comprehensive validation for all fields
- User-friendly error messages
- Profile auto-creation on first view
- Responsive design using Tailwind CSS
- SVG icons for profile details
- Friend/follower statistics display
- Support for viewing other users' profiles
- Authentication: All routes protected by
auth:sanctummiddleware - Validation: All inputs validated server-side
- File Upload Security:
- Only image files allowed
- File size limited to 2MB
- Uses Laravel's built-in file upload handling
- XSS Protection: Blade templating escapes output by default
- CSRF Protection: Forms protected by Laravel's CSRF middleware
Potential improvements for future iterations:
- Profile privacy settings (who can view profile)
- Cover photo upload
- Profile completion percentage indicator
- Social media links section
- Profile activity timeline
- Email change verification
- Profile field visibility controls
- Profile badge/verification system
app/Http/Livewire/ShowProfile.phpapp/Http/Livewire/EditProfile.phpresources/views/livewire/show-profile.blade.phpresources/views/livewire/edit-profile.blade.phpresources/views/user-profile/show.blade.phpresources/views/profile/edit.blade.phptests/Feature/ProfileTest.phpPROFILE_IMPLEMENTATION.md(this file)
app/Models/User.php(added bio to fillable, added profile relationship)routes/web.php(added profile routes)
- The implementation uses Laravel Jetstream's existing profile photo functionality
- Bio field is stored in the
userstable (added by migration2026_02_15_210000_add_bio_to_users_table.php) - Profile is automatically created when first accessed if it doesn't exist
- All routes are protected by authentication middleware
- The implementation follows Laravel and Livewire best practices
- Code review completed with all issues addressed
- Security scan passed with no vulnerabilities detected