I’m having trouble making API calls to RapidAPI from my Laravel controller. I keep getting a class not found error when trying to use the HTTP client library. Can someone help me figure out what’s wrong with my setup?
Here’s what I’m trying to do in my controller:
public function handleSubmission(Request $request)
{
Profile::create(
request()->validate([
'first_name' => ['required','max:255'],
'last_name' => ['required','max:255'],
],
[
'first_name.required' => 'First name is required',
'last_name.required' => 'Last name is required'
]));
$requestHeaders = array('Accept' => 'application/json');
$apiResponse = Unirest\Request::post("RAPIDAPI_ENDPOINT",
array(
"X-RapidAPI-Key" => "MY_API_KEY"
)
);
dd($apiResponse);
return view("success");
}
The error I’m getting:
Class ‘App\Http\Controllers\Unirest\Request’ not found
Is there a better way to make RapidAPI calls in Laravel? Maybe using Guzzle or the built-in HTTP client? Any suggestions would be appreciated!