1 回答
TA贡献1765条经验 获得超5个赞
我能够通过创建一个会话表来解决它
php artisan session:table
composer dump-autoload
php artisan migrate
然后在我的控制器中
public function authenticated(Request $request,User $user)
{
if(Auth::check())
{ //check if the user is logged in or not
$user = Auth::user();
// $login = Session::where('user_id', Auth::id())->count();
$login = DB::table('sessions')->where('user_id', Auth::id())->count();
// dd($login);
if ($user->isBasic())
{
if ($login > 0)
{
Auth::logout();
session()->flash('logout', "You are Logged in on other devices");
return redirect('login');
}
return redirect(route('welcome'));
}
elseif ($user->isCouple())
{
if ($login > 1)
{
Auth::logout();
session()->flash('logout', "You are Logged in on other devices");
return redirect('login');
}
return redirect(route('welcome'));
}
elseif ($user->isFamily())
{
if ($login > 5)
{
Auth::logout();
session()->flash('logout', "You are Logged in on other devices");
return redirect('login');
}
return redirect(route('welcome'));
}
}
else
{
return redirect(route('welcome'));
}
}
- 1 回答
- 0 关注
- 250 浏览
添加回答
举报