I am new to Laravel. I am attempting to pass data from one application (App 1) to the database of another application (App 2). I am dizzy from the tutorials and articles I have studied on APIs and Laravel and Guzzle. I have managed to patch something together to create a new record, but it is inserted into the wrong database: App 1's DB instead of App 2's.
Route in web.php in App 1:
Route::get('post-registrant', [DataController::class, 'postRequest']);
postRequest() in DataController
public function postRequest(Request $request)
{
$client = new \GuzzleHttp\Client();
$url = 'http://thepipeline.localhost/api/v1/registrants/store';
$form_params = [
'email' => '[email protected]',
'first_name' => 'John',
'last_name' => 'Smith',
/. . . .
];
$response = $client->post($url, ['form_params' => $form_params]);
$response = $response->getBody()->getContents();
}
The $url value above is the route to the API in App 2.
http://thepipeline.localhost/api/v1/registrants/store
App 2 route in api.php
Route::post('v1/registrants/store', [RegistrantsController::class, 'store']);
store() in RegistrantsController in App 2
public function store(Request $request)
{
$registrant = Registrant::create($request->all());
return response()->json('Successfully added');
}
On my local machine, I have a DB for App 1 and a DB for App 2. The table I want to add the data into is App2.registrants but the data is being inserted into App1.registrants
If anyone can help identify what is wrong, if not everything, I'd appreciate it.