Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Aronaman's avatar

how to trigger both create and api request

hello guys

while adding every new recordin DB, i want to send api request .

it is possible whie the user create new record using form can send api request same time??

    public function store(Request $request)
    { 
	$org=$request->all();
        $Org = Organization::create($org);

	// here i want to send api request like this

     $client = new \GuzzleHttp\Client(["base_uri" => "http://server.test"]);

       $response = $client->post("/api/post", $Org );//it should also return (problem 1)

//redirect the normal 
return redirect()->route('Orgs.index');

   }

how can i mange both return for api and normal ??

0 likes
1 reply
frankielee's avatar

for GuzzleHttp

 $response = (new GuzzleHttp\Client)->post('your_url.com', [
        "form_params" => [
		"dataIndex" :"dataValue"
        ],
    ]);
$decoded = json_decode((string) $response->getBody(), true);

Please or to participate in this conversation.