Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data in Laravel using POST method in JSON Object?

here is my route.php

Route::post('users' , array('uses'  => 'Userscontroller@index'));

This is my Userscontroller.php

public function index()
    {
        $email_id = Input::get('email_id');
        $name = Input::get('name');

        return $email_id. ' ' .$name;
    }

When i run this in postman I get error as

'>' unexpected in JSON

.

Where m I missing?

Thank You.

like image 430
Bhavin Shah Avatar asked Jun 29 '16 07:06

Bhavin Shah


1 Answers

if you send json like this:

{"user":{"name":"abc","code":134}}

in laravel controller:

$data =  $request->json()->all(); //read json in request
return response()->json($data);  //send json respond
like image 51
dinuka saminda Avatar answered Nov 09 '22 23:11

dinuka saminda