如何获取此变量的值? [英] How can I get the value of this variable?
问题描述
在注销功能中,我需要获取$ time的值.用户登录时,该变量是在其他函数中声明的.
In logout function, I need to get the value of $time. This variable was declared in other function, when user logged in.
Broadcast::channel('chat', function ($user) {
$ip = Request::ip();
$time = now();
if (auth()->check() && !session()->has('name')) {
UserInfo::storeUser();
session()->put('name',$user->name);
return [
'id' => $user->id,
'ip' => $ip,
'name' => $user->name,
'joined' => $time,
];
}
});
当用户注销时,我必须检查他的"id"和"joined"的值.我该怎么办?
When user logged out, I have to check his 'id' and value of 'joined'. How can I do this?
public function logout() {
$id = auth()->id();
$info = \App\UserInfo::where('id', $id)
-> where('joined', $time)
->update(['left' => now()]);
auth()->logout();
session()->forget('name');
session()->put('left',now());
return redirect('/');
}
推荐答案
您必须使用主唯一键作为ID,并创建一列"user_id"以在其中存储auth()-> id桌子.在加入/启动登录会话时,将"id"存储在应用程序中作为"session_id".
You must use a primary unique key as id and make a column 'user_id' for storing the auth()->id in the table. While joining/starting log in session, store the 'id' in application as 'session_id'.
您可以通过使用id来获得"joined"值,
You can get the 'joined' value by using id as follows,
$joined = \App\UserInfo::where('id', auth()->session_id)
->select('joined')
->first()
->joined;
在会话结束时,使用以下ID更新左侧的详细信息,
At end of session, update the left details with the id as follows,
$info = \App\UserInfo::where('id', auth()->session_id)
->update(['left' => now()]);
这篇关于如何获取此变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!