lundi 9 janvier 2017

Angular http post to Laravel backend Request always empty

I have a problem that i don't know how to solve. I use AngularJS 1 to make a post to my backend (Laravel 5.1). The post is successful from AngularJS.

In my Laravel controller i use Request to recieve the posted data from AngulrJS but the $request->all() is always empty and i dont know why.

I have i missed something in my post request?

LARAVEL ROUTE:

Route::post('/signup','SignupController@Signup');


LARAVEL CONTROLLER:
<?php


namespace App\Http\Controllers;
use Illuminate\Http\Request;

class SignupController extends Controller
{
    public function Signup(Request $request){


       dd($request->all()); <-- is always empty
    }  
}

ANGULARJS POST:

.controller('SignupCtrl',function($scope,$http,$state){ 

  $scope.Signup = function($params){

        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        $http.post('http://localhost:8888/vemhamtar/public/signup',{"name":$params.name,"phone":$params.phone,"email":$params.email,"password":$params.password})
        .success(function(response){

          $params.name = "";
          $params.phone = "";
          $params.email = "";
          $params.password = "";
          $state.go("app.contacts");

        })
        .error(function(error){
          console.log(error);
        });
  };
})



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire