douxian4323 2015-12-01 20:59
浏览 46
已采纳

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

This is my first time implementing OAuth to my projects. I found a walkthrough on github for laravel-5 oriceon/oauth-5-laravel. I followed all the steps correctly. However when I get to the controller function I get an error saying:

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

Here is my controller function:

    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);
    }
}

In the app you can see that i did add the correct provider and alias:

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

In my view I call the route that leads to the correct controller function and I keep arriving to this error. What could it be that does this? Should the function be calling to the provider or something? Thanks for looking at this Stack!

  • 写回答

1条回答 默认 最新

  • douzhi1879 2015-12-01 21:24
    关注

    First up, I hope your view isn't calling a route- that's backwards. Routes are used immediately to determine the controller, which is then used to determine and respond with the proper view.

    ... That aside, Request is the name of a facade in Laravel. That's why the error message says it's looking for the get() method on the Illuminate\Support\Facades\Request class. You'll want to namespace the Request class you're using so that it's able to use the correct get() method. Depending on your version, I do this with use Illuminate\Http\Request; at the top of my controller file (immediately after the namespace declaration for the controller).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)