0

I'm trying to receive JSON with Laravel like this:

Controller:

 public function index(Request $request) { dd(Input::all()); } 

Also tried this:

dd(Request::json()->all()); 

But it's both not working. This is the test Json I send with postman:

{“parameters” : [{ “email”:”[email protected]", “password”:”testtesttest” }] } 
4
  • dd( $request->input('<parameter_name>') ) ; should be enough Commented Jan 5, 2016 at 9:25
  • how are you sending this with postman? raw? Commented Jan 5, 2016 at 9:40
  • Yes sending raw. But @Moppo when I do for example dd( $request->input('<parameter_name>') ) ; it returns null. Commented Jan 5, 2016 at 9:41
  • so probably you are not receiving any parameter with the request. Are you sure the json data is sent? Commented Jan 5, 2016 at 9:43

1 Answer 1

1

Try sending your Json like this:

{"parameters": [{"email":"[email protected]","password":"testtest"}]} 

It probably thinks it isn't formatted properly and discards it.

You may want the Content-Type: application/json header set as well.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes had to turn header to application/json. Now when I do: $test = $request->input('parameters'); and it returns everything how could I only receive "email". When I do $request->input('email'); that's not working?
@jamie $request->input('parameters')['email']
@naneri Thanks but that's not working it's telling me: Undefined index: email
I am not sure what version you are on but ... $request->input('parameters.0.email') or $request->input('parameters.*.email') to get all the possible emails in there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.