简体   繁体   中英

Laravel Auth::attempt() fails

When I register a new user and I want to sign him in by using auth attempt it doesn't work while the user is saved to database

static function register()
{
    if(self::$validate['message'])
    {
        $user = User::create([
            'name' => self::$values['name'],
            'email' => self::$values['email'],
            'password' => Hash::make(self::$values['password'])
        ]);

        Auth::attempt($user,true);
        Auth::attempt($user->only(['email','password']));

        return result::repsonse(true);
    } else 
        return self::$validate;
}

You can use Auth::login() method

static function register()
{
    if(self::$validate['message'])
    {
        $user = User::create([
            'name' => self::$values['name'],
            'email' => self::$values['email'],
            'password' => Hash::make(self::$values['password'])
        ]);

        Auth::login($user);

        return result::repsonse(true);
    } else 
        return self::$validate;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM