php - Laravel update password errors -


hi i'm trying update user password using ajax keep getting 500 error.what i've done wrong here 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 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 missing required token in post , tokenmismatchexception being fired.

try putting meta-tag in head section:

<meta name="_token" content="{{ csrf_token() }}"> 

and add in js file:

$.ajaxsetup({   headers: {'x-csrf-token': $('meta[name="_token"]').attr('content')} }); 

Comments