Support the ongoing development of Laravel.io →
Requests Forms Configuration

Hi i'm trying to update user password using ajax but i keep getting 500 error.What i've done wrong #Here is my controller

public function newPass(Request $request)
	{
		User::where('id','=', Auth::user()->id)->update(['password' => Hash::make($request->password)]);
		return response()->json(array('mess'=>'Update success'));
	}

Here is ajax

$(document).ready(function() {
    $('#btnNewPass').click(function(event) {
        event.preventDefault();
        var pass=$("#password").val();
        $.ajax({
            url: '/updatePass',
            type: 'POST',
            data: {pass: pass},
        })
        .success(function(data) {
         alert(data.mess);
     })
        .error(function() {
            alert("Error");
        });
        

        
    });
});

The routes

Route::post('/updatePass','Auth\PasswordController@newPass');
Last updated 3 years ago.
0
Solution

Change

data: {pass: pass},

for

data: {password: pass},
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.