Anyone can help me login user with Laravel, this is my try:
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);
}
This is error:
Argument 1 passed to Illuminate\Auth\Guard::__construct() must be an instance of Illuminate\Contracts\Auth\UserProvider, none given, called in /home/comment/public_html/bild/app/AuthenticateUser.php on line 31 and defined
You can't just instantiate Guard
because it has dependencies that need to be injected when creating it. This is the constructor:
public function __construct(UserProvider $provider,
SessionInterface $session,
Request $request = null)
You have a few options:
Auth::loginUsingId(1);
$auth = app('auth');
$auth->loginUsingId(1);
In the constructor of the class you want to use this:
public function __construct(\Illuminate\Auth\Guard $guard){
$this->auth = $guard;
}
And in your method:
$this->auth->loginUsingId(1);
If you're getting
Trait 'Illuminate\Auth\UserTrait'
That sounds a lot like Laravel 4 to me (Laravel 5 doesn't have this trait anymore) is it possible that you are migrating your application? Take a look at the new default User
model on github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With