Laravel Socialite软件包错误

时间:2018-07-12 15:13:20

标签: php laravel laravel-socialite

尝试使用Google或Facebook登录时,出现错误提示。

  

传递给Illuminate \ Auth \ Guard :: login()的参数1必须实现   Illuminate \ Contracts \ Auth \ Authenticatable界面,给定null

我在使用Laravel的社交名流包。有什么问题,我无法解决。我是第一次使用laravel Socialite软件包

use App\User;

use App\Http\Controllers\Controller;

use Illuminate\Auth\Events\Registered;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Validator;

use Illuminate\Foundation\Auth\RegistersUsers;

use Laravel\Socialite\Facades\Socialite;


class RegisterController extends Controller




{





protected function create(array $data)

    {
        return User::create([

            'name' => $data['name'],

            'email' => $data['email'],

            'password' => bcrypt($data['password']),

            'user_type' => 'user',

            'active_status' => '1'
        ]);
    }

    public function redirectToProvider()


    {

        return  Socialite::driver('facebook')->redirect();


    }

 public function handleProviderCallback()

    {



try{


$socialuser = Socialite::driver('facebook')->stateless()->user();



}  

catch(exception $e){


return redirect('/');

}

$user=User::where('facebook_id',$socialuser->getid())->first();

if(!$user)

User::create([

'facebook_id'=>$socialuser->getid(),

'email'=>$socialuser->getemail(),

'name'=>$socialuser->getname(),
    ]);

auth()->login($user);

    return redirect()->to('/dashboard');
    }
}

请帮助我。我是初学者。 谢谢

1 个答案:

答案 0 :(得分:0)

检查您的用户模型,确保其实现了Authenticable。我猜想它当前扩展了Model,但没有使用Authenticable。将其张贴在此处以供使用以确认它看起来还可以。