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');
I think you are missing the required token in your post and the TokenMismatchException is being fired.
Try putting this meta-tag in the head section:
<meta name="_token" content="{{ csrf_token() }}">
And then add this in your js file:
$.ajaxSetup({
headers: {'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')}
});