当前位置: 首页 > 知识库问答 >
问题:

Laravel 5.7社交名媛类型错误:参数1传递给Illumb\Auth\SessionGuard::login()

须景辉
2023-03-14

我使用solcialite登录Laravel通过Gihub,但有问题登录。我得到一个错误:Symfony\组件\调试\异常\FatalThrowableError(E_RECOVERABLE_ERROR)类型错误:参数1传递给照明\Auth\SessionGuard::登录()必须实现接口照明\合同\Auth\身份验证,空给定,调用 /var/www/html/testio/vendor/laravel/framework292线/src/Illuminate/Auth/AuthManager.php

我的登录控制器:

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Socialite;
use App\User;
use Auth;


class LoginController extends Controller
{
    use AuthenticatesUsers;


    protected $redirectTo = '/home';


    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    /**
     * Redirect the user to the GitHub authentication page.
     *
     * @return \Illuminate\Http\Response
     */
    public function redirectToProvider()
    {
        return Socialite::driver('github')->redirect();
    }

    /**
     * Obtain the user information from GitHub.
     *
     * @return \Illuminate\Http\Response
     */
    public function handleProviderCallback()
    {
        $github_user = Socialite::driver('github')->user();

        $user = $this->userFindorCreate($github_user);

        Auth::login($user, true);

        return redirect('/home');


        // $user->token;
    }
    public function userFindorCreate($github_user){
        $user = User::where('provider_id', $github_user->id)->first();

        if(!$user){
            $user = new User;
        $user->name = $github_user->getName();
        $user->email = $github_user->getEmail();
        $user->provider_id = $github_user->getid();
        $user->save();
        }
    }
}

我的User.php模型:

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Foundation\Auth\User as AuthUser;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'email',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}

创建用户表:

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->nullable();
            $table->string('email')->unique();
            $table->string('password')->nullable();
            $table->string('provider_id');
            $table->rememberToken();
            $table->timestamps();
        });
    }

该死,我做错了什么?

共有1个答案

江正德
2023-03-14

我错过了返回$用户;上一个函数:

html prettyprint-override">public function userFindorCreate($github_user){
        $user = User::where('provider_id', $github_user->id)->first();

        if(!$user){
            $user = new User;
        $user->name = 'jojo';
        $user->email = $github_user->getEmail();
        $user->provider_id = $github_user->getid();
        $user->save();
        }

        return $user;
    }
 类似资料:
  • 修改我的注册刀片。我添加了2个触发用户注册的附加功能。我需要的数据被保存到适当的表中,但是我有这个错误, Argument 1传递给Illumate\Auth\SessionGuard::登录()必须实现接口Illumate\合同\Auth\身份验证,布尔值给定,在第35行调用E:\wamp64\www\aftspirdit-appzcoder\供应商\laravel\框架\src\Illumat

  • 传递给Illumate\Auth\EloquentUserProvider的参数1::validateCreentials()必须是Illumate\合同\Auth\身份验证的实例,应用程序\模型\用户给定的实例,在D:\xampp\htdocs\后端\电子商务\供应商\laravel\框架\src\Illumate\Auth\SessionG中uard.php第384行----我有这个问题请帮我

  • 帮助我理解并解决这些错误。 错误: Symfony\Component\Debug\Exception\FatalThrowableError(E\u RECOVERABLE\u ERROR)类型错误:传递给App\Http\Controllers\Auth\LoginController::authenticated()的参数1必须是App\Http\Controllers\Auth\Reque

  • 请帮我做一个购物车的项目。我试图将产品添加到basket,但在添加新产品时得到了这个错误:Type error:传递给decility\common\collections\arraycollection::__construct()的参数1必须是array类型,对象给定,在C:\users\Angel's\desktop\untitled2\vendor\decility\orm\lib\dec

  • 我使用的是Laravel5.2。 我在表中添加了一个名为的新字段,并将其包含在视图和 我还做了一个检查,看看用户是否将使用一个保留的slug作为他的用户名,如果是,我抛出一个错误,如果用户名是好的,我保存在数据库中。 我正在检查2个保留的段塞和-这就是我保留的全部。 如果我取消检查,数据将正常保存在数据库中,包括保留的slug。所以我必须做检查。 然而,当我应用检查时,我得到了这个错误 Sessi

  • 有时对一个类的某些方面进行 参数化(parameterize)是很有用的。例如, 你可能需要管理不同版本的 gem 软件包,既可以为每一种版本创建分离的单独的类, 也可以使用继承和覆盖,为一个类传递一个版本号作为参数。 操作步骤 声明参数作为如下类定义的一部分: class eventmachine( $version ) { package { "eventmachine": pro