Laravel 5.5:Auth不起作用

时间:2018-01-12 14:33:28

标签: php laravel-5

我使用以下代码使用Auth。

登录
public function login(Request $request) {
    $email = $request->input('email');
    $password = $request->input('password');
    $remember = $request->input('remember');
    if (Auth::attempt(['email' => $email, 'password' => $password], $remember))
    {
        return redirect()->intended('home');
    }
    return view('app.login')->with('errors', 1);
}

尝试函数返回true,因此散列不应该是问题。当我被重定向到' home'页面,我还没有通过身份验证。未显示刀片模板中的@auth部分,并且Auth :: check()返回false。似乎auth信息没有存储在会话中 我是否需要修改我的用户模型?这是我的config / auth:

return [

    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],

        /*
        'users' => [
            'driver' => 'database',
            'table' => 'users',
        ],
        */
    ],

    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],

];

我的模特:

class User extends Authenticatable 
{
    use Notifiable;

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

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

0 个答案:

没有答案