oriceon/oauth-5-laravel安装控制器请求错误


oriceon/oauth-5-laravel install controller request error

这是我第一次在项目中实现OAuth。我在github上找到了一个关于laravel-5 oriceon/oauth-5-laravel的演练。我正确地完成了所有步骤。然而,当我进入控制器功能时,我收到一个错误,说:

Call to undefined method Illuminate'Support'Facades'Request::get()

这是我的控制器功能:

    public function loginWithFacebook(Request $request)
{
    // get data from request
    $code = $request->get('code');
    // get fb service
    $fb = 'OAuth::consumer('Facebook');
    // check if code is valid
    // if code is provided get user data and sign in
    if ( ! is_null($code))
    {
        // This was a callback request from facebook, get the token
        $token = $fb->requestAccessToken($code);
        // Send a request with it
        $result = json_decode($fb->request('/me'), true);
        $message = 'Your unique facebook user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
        echo $message. "<br/>";
        //Var_dump
        //display whole array.
        dd($result);
    }
    // if not ask for permission first
    else
    {
        // get fb authorization
        $url = $fb->getAuthorizationUri();
        // return to facebook login url
        return redirect((string)$url);
    }
}

在应用程序中,你可以看到我添加了正确的提供商和别名:

'OAuth' => Artdarek'OAuth'Facade'OAuth::class,
Artdarek'OAuth'OAuthServiceProvider::class,

在我看来,我调用了导致正确控制器功能的路径,并且我不断地到达这个错误。是什么干的?函数应该调用提供程序还是其他什么?谢谢你看这个Stack!

首先,我希望您的视图没有调用路由——这是向后的。路线被立即用于确定控制器,然后用于确定并以正确的视图进行响应。

除此之外,Request是Laravel中立面的名称。这就是为什么错误消息说它正在Illuminate''Support''Facades''Request类上查找get()方法。您需要为正在使用的Request类命名名称空间,以便它能够使用正确的get()方法。根据您的版本,我会在控制器文件的顶部使用use Illuminate'Http'Request;(紧接在控制器的命名空间声明之后)执行此操作。