任何人都可以帮我用Laravel登录用户,这是我的尝试:
public function execute($hasCode){
if(!$hasCode) return $this -> getAuthorizationFrist();
$user = $this->socialite->driver('facebook')->user();
echo $user->getNickname();
echo $user->getName();
echo $user->getEmail();
echo $user->getAvatar();
$login = new Guard();
$login ->loginUsingId(1);
}
这是错误:
传递给Illuminate \ Auth \ Guard :: __ construct()的参数1必须是Illuminate \ Contracts \ Auth \ UserProvider的实例,没有给出,在第31行的/home/comment/public_html/bild/app/AuthenticateUser.php中调用并定义
2 回答
您不能只是实例化
Guard
,因为它具有在创建时需要注入的依赖项 . 这是构造函数:你有几个选择:
1.使用立面:
2.使用IoC容器:
3.使用依赖注入(推荐):
在类的构造函数中,您要使用此:
在你的方法中:
如果你得到了
这对我来说听起来很像Laravel 4(Laravel 5不再具有这种特性)你有可能正在迁移你的应用程序吗?看看新的default User model on github
使用Auth Facade:
Relevant laravel docs article