0

Here is my post angular request

 route.service('MetaDataService',function ($http) {


   $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

    this.newItem = function (url,data) {
           console.log(data);
           return $http.post('/'+url,data).then(function (response) {
               return response.data.status;
           });
       }

    });

Laravel controller

public function store(Request $request)
{
   dd($request->all());
}

dd($request->all()) returns [] array.

Also i've logged the data before the request (console.log(data))it will gives the ouptut

Request header

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en;q=0.8,en-US;q=0.6,pl;q=0.4
Connection:keep-alive
Content-Length:2
Content-Type:application/x-www-form-urlencoded
Cookie:XSRF-TOKEN=eyJpdiI6ImluZmIwSmRNZ09MR0oxWEtzUzg0enc9PSIsInZhbHVlIjoiMXZLV1ZlN01YQm1jOVhvWXh4QlpuSXcxTVlSXC9jWStYYjlGWU5xeUFDWnhHQksrc0dvUzBhcFhvbCtFWVozSUxmNjhGT0s3aHRqM2UyV3hMZXJzR0dBPT0iLCJtYWMiOiI2NzIwYmQwMjAyODlkMmE0OTY5ODVkMTFhNmNkZTJkMTkzMDM2MjZmMWQ2ODBlNjJmODFhYjEwMzMwOGM5N2RiIn0%3D; laravel_session=eyJpdiI6InR3OURXNVNBRkQzcDM5TFlJMm9BaFE9PSIsInZhbHVlIjoiWHFOZG1cL2kzd3VFcDN1eWZ1SFk3WTRsM3Q0dmlRQzhuaVhaNHJzUzY0bTVpR2VrdVAwUkZPV0YzaHo4R01iSXB1QXZcL0k1QUVJejB2Y1wvM0JEa0xtdUE9PSIsIm1hYyI6IjFlOTU2OGNkYjM5ZmRlYmNmMGYwZGJiOGE4OTYwY2Y5YjFmYjg0ZDZkOTU4NjhkMmVkZjU0ZTkxNzVlYWRmZjAifQ%3D%3D
Host:localhost:8000
Origin:http://localhost:8000
Referer:http://localhost:8000/home
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
X-XSRF-TOKEN:eyJpdiI6ImluZmIwSmRNZ09MR0oxWEtzUzg0enc9PSIsInZhbHVlIjoiMXZLV1ZlN01YQm1jOVhvWXh4QlpuSXcxTVlSXC9jWStYYjlGWU5xeUFDWnhHQksrc0dvUzBhcFhvbCtFWVozSUxmNjhGT0s3aHRqM2UyV3hMZXJzR0dBPT0iLCJtYWMiOiI2NzIwYmQwMjAyODlkMmE0OTY5
5
  • can you show us a sample data ? Commented May 18, 2017 at 11:11
  • [name: "hello"] output of console.log(data) Commented May 18, 2017 at 11:12
  • @Demonyowh any idea?? Commented May 18, 2017 at 11:20
  • are you getting any error in console like Access-Control-Allow-Origin? Commented May 18, 2017 at 11:33
  • nop there is no CORS issues Commented May 18, 2017 at 11:34

3 Answers 3

1

Actually the angular js sends as raw data which could be retrieved by:

file_get_contents("php://input");

In Laravel there is a preferred or recommended way:

$request = Request::instance();
$content = $request->getContent();

OR

$content = Request::getContent();

Happy Coding!

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

Comments

0

try to access as,

dd($request->json()->all());

3 Comments

Tried but returns empty array
Check weather file_get_contents('php://input') gives you something. or you can use $request->name
Hmmmm... waiting for same.
0

Are you using the correct Request?

use Illuminate\Http\Request;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.