当前位置:  开发笔记 > 编程语言 > 正文

在null上调用成员函数set()

如何解决《在null上调用成员函数set()》经验,为你挑选了1个好方法。

我试图在laravel 5中使用oauth谷歌,但我收到了错误.任何人都可以帮我解决这个问题.

以下是我的档案,请查看

.ENV

GOOGLE_ID = 'mygoogleId' 
GOOGLE_SECRET = 'mysecretID'
GOOGLE_REDIRECT = http://localhost:8090/users

services.php

'google' => [
        'client_id' => env('GOOGLE_ID'),
        'client_secret' => env('GOOGLE_SECRET'),
        'redirect' => env('GOOGLE_REDIRECT'),
    ],

AuthController
public function redirectToProvider() {
        return Socialite::driver('google')->redirect();
    }

public function handleProviderCallback()    {
        $user = Socialite::driver('google')->user();
            console.log($user);
}

routes.php文件

Route::get('google', 'Auth\AuthController@redirectToProvider');
Route::get('google/callback', 'Auth\AuthController@handleProviderCallback');

//I have set the providers and aliases in app.php.

这是我收到错误的代码

//在set()方法上

public function redirect()
{
    $state = str::random(40);

    if ($this->usesState()) {
        $this->request->getSession()->set('state', $state);
    }
    return new RedirectResponse($this->getAuthUrl($state));
}

提前致谢..



1> Cowboy..:

嘿如果您使用laravel 5.2,这对我有用.

将您的控制器放在"web"中间件中.喜欢,

Route::group(['middleware' => 'web'], function() {
   Route::get('google', 'Auth\AuthController@redirectToProvider');
   Route::get('google/callback', 'Auth\AuthController@handleProviderCallback');
});

并确保内核文件已注册中间件类.

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        \Perkweb\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \Perkweb\Http\Middleware\VerifyCsrfToken::class,
    ],

    'api' => [
        'throttle:60,1',
    ],
];

推荐阅读
地之南_816
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有