【问题标题】:How to fetch Rapidapi in laravel Controller?如何在 laravel Controller 中获取 Rapidapi?
【发布时间】:2020-04-13 14:23:17
【问题描述】:

我正在尝试在我的 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");
   }

错误

找不到类“App\Http\Controllers\Unirest\Request”

【问题讨论】:

    标签: laravel unirest rapidapi


    【解决方案1】:

    您需要导入Unirest\Request 类。

    <?php
    
    namespace Your\Namespace;
    
    use Unirest\Request;
    
    class YourClass{
    ...
    

    如果您不导入它,默认情况下它将在当前命名空间中查找类(在您的情况下为App\Http\Controllers)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-27
      • 1970-01-01
      相关资源
      最近更新 更多