PASSING PARAMETERS VIA JSON ON LARAVEL

Asked

Viewed 236 times

0

Good morning Everybody. I’m brand new in PHP and need a help with an api implementation.

I basically have a midleware that does a get or post on a third party’s api. Then, a user gets a get at a url that he donated to him and he gets back the guy’s api. However, I needed to make a move so that even the post is through a get call.

An example:

public function ProductVariations($level){
    $this->get("api/catalog_system/pub/products/variations/".$level[0]);
    return $this->result();
}

And my Route :

$route->get("productVariations", "Produto@ProductVariations");

The same goes for the Post of my app:

$route->get("createuser", "User@createUser");

--

public function createUser(){
    $this->post("api/license-manager/users", [
        "email" => "[email protected]",
        "name" => "Fabio Teste"
    ]);
    return $this->result();
}

When I enter the parameters directly, absolute success. But I cannot pass this body via post $. post(url, [{xxx xxx}]).

How to make my post receive the body as a variable or similar.

Vlwww

  • Tried to declare the vector before putting in the body?

2 answers

0

public function createUser(){
    $this->post("api/license-manager/users", [

    //CHAMADA DIRETA - PASSANDO EMAIL E NAME
        "email" => "[email protected]",
        "name" => "Fabio Teste 2"

    //A CHAMADA A CIMA DEVE SER SUBSTITUIDA POR UM DATA PASSADO NO AJAX
        data

    ]);
    return $this->result();
}

That’s the idea of how it should work

var data = {
    'email': "[email protected]",
    'name': "Rodrigo 001323"
}
$.ajax({
  type: "POST",
  url: window.location.origin + '/midleware/createuser/',
  data: JSON.stringify(data),
  success: function(data){
        console.log(data)
  }
});

0

Receives the Request as dependency Injection and picks up body with the method input, then spend it together when doing the post for third party api.

public function createUser(\Illuminate\Http\Request $request)
{
    $this->post("api/license-manager/users", $request->input());

    return $this->result();
}
  • It didn’t work. When I step into the dependency injection of error 500

Browser other questions tagged

You are not signed in. Login or sign up in order to post.