| Server IP : 139.59.63.204 / Your IP : 216.73.217.62 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/abyogasms.com/app/Http/Controllers/ |
Upload File : |
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
class UserProfileController extends Controller
{
public function show()
{
$user = auth()->user();
return view('profile.edit', compact('user'));
}
public function update(Request $request)
{
try {
$user = auth()->user();
$validated = $request->validate([
'name' => 'required|string|max:255',
'email' => 'required|email|max:255|unique:users,email,' . $user->id,
'mobile' => 'nullable|string|max:20',
'address' => 'nullable|string|max:500',
'age' => 'nullable|integer|min:1|max:150',
'designation' => 'nullable|string|max:255',
'profileimage' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:2048',
]);
// Handle profile image upload
if ($request->hasFile('profileimage')) {
// Delete old image if it exists
if ($user->profileimage && Storage::disk('public')->exists($user->profileimage)) {
Storage::disk('public')->delete($user->profileimage);
}
// Store new image
$path = $request->file('profileimage')->store('profiles', 'public');
$validated['profileimage'] = $path;
}
// Update user
$user->update($validated);
return redirect()->route('profile.show')
->with('success', 'Profile updated successfully!');
} catch (\Exception $e) {
return back()->withErrors(['error' => 'Failed to update profile: ' . $e->getMessage()]);
}
}
}