title: How to retrieve json data to laravel controller
body: <p>There are questions like this on StackOverflow, that I know.</p>
  
  <p>Trust me, I have tried all the solutions to no avail.</p>
  
  <p>I have been trying to post this json data from angularjs to a laravel controller method:</p>
  
  <pre><code>[
    {
      "id": 2,
      "name": "add-user",
      "display_name": "Add new user",
      "description": "Create a new worker",
    },
    {
      "id": 4,
      "name": "add-role",
      "display_name": "Add role",
      "description": "Add user role",
    }
  ]
  </code></pre>
  
  <p>this is the code that posts this json data to a laravel controller:</p>
  
  <pre><code>$http({
      method: 'POST',
      url:  '/api/roles/assignPermissions/' + name,
      headers: { 'Content-Type' : 'application/json' },
      data: $.param(role_perms)
  }).success(function(data){
      console.log(data);
  });
  </code></pre>
  
  <p>Now in this controller method, I just want retrieve this json data, return it and display it in the console to be sure that I received it in the controller.</p>
  
  <p>Below is the controller and all the attempts I've made to get this json data and return it.</p>
  
  <p><strong>The controller:</strong></p>
  
  <pre><code>public function massAssignPerms(Request $request, $roleName)
  {
      $role = Role::where('name', $roleName)-&gt;first();
  
  
      // this returned nothing
      return json_decode(file_get_contents('php://input'),true); 
  
      // this returned: add-user=&amp;add-role=
      return file_get_contents('php://input');
  
      // returned nothing
      return json_decode($request-&gt;getContent(), true);
  
      // returned empty array []
      return $request-&gt;json()-&gt;all();
  }
  </code></pre>
  
  <p>I am unable to find what's wrong with my code. Or it could be that I'm doing it wrongly?</p>
  
  <p>Any help will be greatly appreciated.</p>