如何在 laravel Controller 中获取 Rapidapi?
How to fetch Rapidapi in laravel Controller?
我正在尝试在我的 laravel 应用程序中使用 unirest 获取 API。我按照文档中给出的所有步骤进行操作,但它向我显示错误。如果 unirest
有更好的选择,请告诉我。提前致谢!
这是我的控制器,
public function store(Request $request)
{
Love::create(
request()->validate([
'name_1' => ['required','max:255'],
'name_2' => ['required','max:255'],
],
[
'name_1.required' => 'You have to Enter Your name',
'name_2.required' => 'You have to Enter Your Crush name'
]));
$headers = array('Accept' => 'application/json');
$response = Unirest\Request::post("API_URL",
array(
"X-RapidAPI-Key" => "API_KEY"
)
);
dd($response);
return view("result");
}
错误
Class 'App\Http\Controllers\Unirest\Request' not found
您需要导入 Unirest\Request
class。
<?php
namespace Your\Namespace;
use Unirest\Request;
class YourClass{
...
如果您不导入它,它将默认在当前命名空间中查找 class(在您的例子中,App\Http\Controllers
)。
我正在尝试在我的 laravel 应用程序中使用 unirest 获取 API。我按照文档中给出的所有步骤进行操作,但它向我显示错误。如果 unirest
有更好的选择,请告诉我。提前致谢!
这是我的控制器,
public function store(Request $request)
{
Love::create(
request()->validate([
'name_1' => ['required','max:255'],
'name_2' => ['required','max:255'],
],
[
'name_1.required' => 'You have to Enter Your name',
'name_2.required' => 'You have to Enter Your Crush name'
]));
$headers = array('Accept' => 'application/json');
$response = Unirest\Request::post("API_URL",
array(
"X-RapidAPI-Key" => "API_KEY"
)
);
dd($response);
return view("result");
}
错误
Class 'App\Http\Controllers\Unirest\Request' not found
您需要导入 Unirest\Request
class。
<?php
namespace Your\Namespace;
use Unirest\Request;
class YourClass{
...
如果您不导入它,它将默认在当前命名空间中查找 class(在您的例子中,App\Http\Controllers
)。