routes.php
Route::get('/register',function(){
$data = 'Register';
return View::make('user.register');
});
Route::post('/register',function(){
$inputData = Input::get('formData');
parse_str($inputData, $formFields);
$userData = array(
'name' => $formFields['name'],
'email' => $formFields['email'],
'password' => $formFields['password'],
'password_confirmation' => $formFields[ 'password_confirmation'],
);
$rules = array(
'name' => 'required',
'email' => 'required|email|unique:users',
'password' => 'required|min:6|confirmed',
);
$validator = Validator::make($userData,$rules);
if($validator->fails())
return Response::json(array(
'fail' => true,
'errors' => $validator->getMessageBag()->toArray()
));
else {
//save password to show to user after registration
$password = $userData['password'];
//hash it now
$userData['password'] = Hash::make($userData['password']);
unset($userData['password_confirmation']);
//save to DB user details
if(User::create($userData)) {
//return success message
return Response::json(array(
'success' => true,
'email' => $userData['email'],
'password' => $password
));
}
}
});
Register.blade.php
<html>
<head>
<link href='//fonts.googleapis.com/css?family=Lato:100' rel='stylesheet' type='text/css'>
<script src="./jquery.js"></script>
</head>
<body>
{!!Form::open(['url'=>'register'],array('id'=>'regForm'))!!}
{!! Form::label('name', 'Name', array('class'=>'control-label')) !!}
{!! Form::text('name', null, array('class'=>'form-control','placeholder'=>'Enter Name')) !!}
<div id ="name_error"></div>
{!! Form::label('email', 'Email', array('class'=>'control-label')) !!}
{!! Form::text('email', null, array('class'=>'form-control','placeholder'=>'Enter Email')) !!}
<div id ="email_error"></div>
{!! Form::label('password', 'Password', array('class'=>'control-label')) !!}
{!! Form::password('password', array('class'=>'form-control', 'placeholder'=>'Password')) !!}
<div id ="password_error"></div>
{!! Form::label('password_confirmation', 'Confirm Password',array('class'=>'control-label')) !!}
{!! Form::password('password_confirmation', array('class'=>'form-control','placeholder'=>'Confirm Password')) !!}
{!! Form::submit('Register', array('class'=>'btn btn-warning btn-lg')) !!}
{!! Form::close() !!}
<div id="successMessage"></div>
<script>
$( "#regForm" ).submit(function( event ) {
event.preventDefault();
var $form = $( this ),
data = $form.serialize(),
url = $form.attr( "action" );
var posting = $.post( url, { formData: data } );
posting.done(function( data ) {
if(data.fail) {
$.each(data.errors, function( index, value ) {
var errorDiv = '#'+index+'_error';
$(errorDiv).addClass('required');
$(errorDiv).empty().append(value);
});
$('#successMessage').empty();
}
if(data.success) {
$('.register').fadeOut(); //hiding Reg form
var successContent = '<div class="message"><h3>Registration Completed Successfully</h3><h4>Please Login With the Following Details</h4><div class="userDetails"><p><span>Email:</span>'+data.email+'</p><p><span>Password:********</span></p></div></div>';
$('#successMessage').html(successContent);
} //success
}); //done
});
</script>
</div>
</body>
</html>
So my problem is this I have installed the laravel on my xampp server . So i want to send a ajax request using post but whenever i send the the request it shows me 500 Internal Server Error and TokenMismatchException . I Have search everything on google and tried every single but still getting the same error . I am not able to understand from where the problem is coming , so please if any one can help me