i have 2 web apps whereby on adding data on one system,SYSTEM A,products table in its db, it automatically adds data to the other system table,SYSTEM B, with similar name in the database.i am using a curl request to send data to the api which then posts data to the table of the database.I have added everything but still the request doesnt function.i havent understood where i have gone wrong with my code.
here is my save function in system A
public function saveproduct(Request $request)
{
if($request->ismethod('post')){
$data=$request->all();
$product=new Product;
$product->name=$data['name'];
$product->description=$data['description'];
$product->save();
$productsdata=$data;
$url="http://systemb/api/push_products";
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$productsdata);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('content-Type','application/json'));
$result=curl_exec($ch);
// dd($productsdata);die();
curl_close($ch);
}
}
here is the post route in the systemb on the api.php
Route::namespace('api')->group(function(){
Route::post('/push_products', 'APIFcController@savefromsystemA');
});
here is the savefromsystemA function in the APIFcController
public function savefromsystemA(Request $request)
{
if($request->ismethod('post')){
$data=$request->all();
$product=new Product;
$product->name=$data['name'];
$product->description=$data['description'];
$product->save();
}
}