To make a POST request using Laravel's HTTP client, you can use the post method and pass in the URL and data as parameters. Here's an example:
$url = "https://example.com/api";
$data = [
'name' => 'John Doe',
'email' => '[email protected]',
];
$response = Http::post($url, $data);
dd($response->json());
In this example, we're making a POST request to https://example.com/api with the data ['name' => 'John Doe', 'email' => '[email protected]']. The dd function is used to dump and die the response as a JSON object.
If you're getting a 419 CSRF token expired error, it means that your request is missing a CSRF token. You can add the CSRF token to your request by including it in the data array:
$data = [
'_token' => csrf_token(),
'name' => 'John Doe',
'email' => '[email protected]',
];
If you're trying to get data from a second application, you can use the get method instead of the post method:
$url = "https://example.com/api/data";
$response = Http::get($url);
dd($response->json());
In this example, we're making a GET request to https://example.com/api/data and dumping the response as a JSON object. You can process the data in the response as needed before returning it to the requesting application.