Untitled

mail@pastecode.io avatar
unknown
php_laravel_blade
a year ago
666 B
2
Indexable
Never
// Kode di bawah merupakan bagian dari controller dalam Laravel

public function updateUserProfile(Request $request, $userId)
{
    $user = User::find($userId);

    $request->validate([
        'name' => 'required',
        'email' => 'required|email|unique:users,email,' . $user->id,
        'password' => 'confirmed|min:6',
    ]);

    $user->name = $request->input('name');
    $user->email = $request->input('email');
    if ($request->input('password')) {
        $user->password = bcrypt($request->input('password'));
    }
    $user->save();

    return redirect()->route('profile')->with('success', 'Profile updated successfully.');
}