I'm using Laravel 4 with Angular JS to handle $http requests using RESTful controllers.
I have a RESTful controller, UserController that has the following functions:
public function getIndex(){
//is Request::get() the correct way to get the parameter?
echo json_encode(array(
'username'=>User::countUsername(Request::get('name')),
'email'=>User::countEmail(Request::get('email'))
));
}
public function postIndex(){
//don't know how to get parameter
}
The $http GET and POST requests I am making are below:
GET
//is this url the correct way to send in my parameters for GET request?
dataString = 'name='+username+'&email='+email;
$http.get('user?'+dataString).success(
//do something with returned json
)
POST
data = {
'username':username,
'email':email,
'password':password
}
$http.post('user', data).success(
//do something
)
The getIndex() method works just fine, although I have doubts on whether I am using the correct procedure.
With the above mentioned, I have two questions:
Is
Request::get()the correct way to retrieve parameters from the XHR GET? Is appendingdataStringto the URL in my Javascript the correct way to send in parameters the RESTful way?How do I retrieve the JSON object sent from my XHR POST? I have tried several methods including
Request::get()andInput::json(), but I've had no luck.
Thanks in advance.