auth :: guard('foo')-> check()在web.php中不起作用

时间:2019-05-14 16:39:01

标签: php laravel authentication

我有一个称为“ Representante”的后卫,需要验证是否有人在web.php文件中登录。当我验证时,它返回false,但在LoginController中返回true。

我正在创建一个登录系统,没有使用Laravel Auth,因为我的用户名和密码存储在differents表中,并且不想麻烦更改auth,因此从0开始的速度会更快

web.php

Route::get('/', function () {
    // Verifica se existe alguém logado, se tiver mostra os pedidos,
    // Se não mostra o login.

        dd(Auth::guard('representante')->check());
        //Here returns FALSE

    if( Auth::guard('representante')->check() || Auth::check() ) {

        return redirect()->route('pedidos.index');
    } else {
        return view('login');
    }

})->name('login');

登录控制器

if (Hash::check($pass, $db_pass->sv_senha)) {

    switch ($type) {
        case 1:

            Auth::login($db_user);
            break;

        case 2:

            Auth::guard('representante')->login($db_user);
            dd(Auth::guard('representante')->user());
            //Here returns TRUE

            break;

    }

    return redirect()->route('pedidos.index');

} else {

    return redirect()->back()->withErrors(['senha' => 'Senha Incorreta'])->withInput();

}

0 个答案:

没有答案
相关问题