I'm having trouble with Laravel 5. I'm getting csrf token but i cant able to post. For registering purpose I'm trying post. But it is showing the token mismatch.
Post method
var registerData = {
'name':customer.name,
'email':customer.email,
'password' :customer.password,
'_token' : customer._token
};
alert(registerData._token);
$http({
method : 'POST',
url : 'http://192.168.0.112/grubsouk/grub/customer',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data : registerData
})
.success(function(data){
console.log(data);
alert("success");
$location.url("/sign");
})
.error(function(data){
alert("error");
})
Get method
$http.get('http://192.168.0.112/grubsouk/admin/getcsrf')
.success(function(data, status, headers, config){
alert("**** SUCCESS ****");
alert(data.token);
$rootScope.token = data.token;
$rootScope.customer = {
_token : $rootScope.token
}
alert(data.token);
})
.error(function(data, status, headers, config){
alert("**** ERROR ****");
alert(status);
})
$state.go('registration');
Add the following in your Controller
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE");