Nav*_*eed 3 php laravel laravel-5
这是我的auth.php:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
],
Run Code Online (Sandbox Code Playgroud)
现在,如果 auser和 anadmin都在同一个浏览器中登录,我如何检查哪个守卫发出了请求?
请注意,无论是谁提出请求,都返回Auth::guard('admin')->check()和。Auth::check()true
我假设您想知道哪个守卫auth()->user()指的是 - 可以通过auth()->guard()
不幸的是,没有一个现有的函数来实际获取守卫的名字。您可以使用auth()->guard()->getName()但返回守卫的会话标识符(即login_guardname_sha1hash),但如果您需要它,您可以提取它:
$guard = auth()->guard(); // Retrieve the guard
$sessionName = $guard->getName(); // Retrieve the session name for the guard
// The following extracts the name of the guard by disposing of the first
// and last sections delimited by "_"
$parts = explode("_", $sessionName);
unset($parts[count($parts)-1]);
unset($parts[0]);
$guardName = implode("_",$parts);
Run Code Online (Sandbox Code Playgroud)